c#登陆问题求解!!!!!

别乱了我眼神 2012-07-12 06:10:28
代码如下
private void UserCheck()
{
string sql = string.Format("select count(*) from Admin where LoginId={0} and LoginPwd={1}", TxtName.Text.Trim(), TxtPwd.Text.Trim());
bool result = DBHelpe.Execulse(sql);
if (result)
{
admin dm = new admin();
dm.Show();
}
namespace WindowsApplication1
{
class DBHelpe
{
public static string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
public static SqlConnection coon = new SqlConnection(connction);
public static bool Execulse(string sql)
{
coon.Open();
SqlCommand cmd = new SqlCommand(sql,coon);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
return true;
}
else
{
return false;
}

}
}
}


连接了数据库,为什么运行输入账号密码,点击登陆 也不提示出错,什么反应也没,卡住了! 到底怎么回事求解!!!!
...全文
119 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你开了无数次con.open,又不关,不卡才怪啊
  • 打赏
  • 举报
回复
修改如下
 public bool UserCheck()
{
bool flag = false;
string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
SqlConnection coon = new SqlConnection(connction);
try
{
coon.Open();
string sql = string.Format("select count(*) from Admin where LoginId='{0}' and LoginPwd='{1}'", TxtName.Text.Trim(), TxtPwd.Text.Trim());
SqlCommand cmd = new SqlCommand(sql, coon);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
flag= true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
coon.Close();
}
return flag;
}
别乱了我眼神 2012-07-12
  • 打赏
  • 举报
回复
public bool UserCheck()
{
string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
SqlConnection coon = new SqlConnection(connction);
try
{
coon.Open();
string sql = string.Format("select count(*) from Admin where LoginId='{0}' and LoginPwd='{1}'", TxtName.Text.Trim(), TxtPwd.Text.Trim());
SqlCommand cmd = new SqlCommand(sql, coon);
int result = (int)cmd.ExecuteScalar();
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
coon.Close();
}
}
提示出错,并非所有的代码路径都有返回值! 哪出错了?
别乱了我眼神 2012-07-12
  • 打赏
  • 举报
回复
即使返回1 那也该跳转吧 关键就是程序没相应了[Quote=引用 4 楼 的回复:]
select count(*) from Admin where LoginId={0} and LoginPwd={1}
int result = (int)cmd.ExecuteScalar();
---------------
这个结果无论神马时候都返回1啊
应该改成select * from Admin where LoginId={0} and LoginPwd={1}
[/Quote]
deepmist 2012-07-12
  • 打赏
  • 举报
回复
select count(*) from Admin where LoginId={0} and LoginPwd={1}
int result = (int)cmd.ExecuteScalar();
---------------
这个结果无论神马时候都返回1啊
应该改成select * from Admin where LoginId={0} and LoginPwd={1}
别乱了我眼神 2012-07-12
  • 打赏
  • 举报
回复
private void button2_Click(object sender, EventArgs e)
{
if (Input())
{
UserCheck();
}
登陆语句
[Quote=引用 2 楼 的回复:]
这样说让人情何以堪,调式一下,看看走到哪里了

你这连接开了也没关,而且语句执行了也确实什么都没做啊,你的登录语句呢
[/Quote]
色拉油 2012-07-12
  • 打赏
  • 举报
回复
这样说让人情何以堪,调式一下,看看走到哪里了

你这连接开了也没关,而且语句执行了也确实什么都没做啊,你的登录语句呢
stiff_neck 2012-07-12
  • 打赏
  • 举报
回复
卡在哪了

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧