代码如下
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;
} }
}
}
连接了数据库,为什么运行输入账号密码,点击登陆 也不提示出错,什么反应也没,卡住了! 到底怎么回事求解!!!!
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;
} }
}
}
连接了数据库,为什么运行输入账号密码,点击登陆 也不提示出错,什么反应也没,卡住了! 到底怎么回事求解!!!!
解决方案 »
- 如何为WINFORM中的DataGridView添加水印
- Type[] tepes 数据问题
- datagridview控件里的combox列的问题
- 求助 我的系统是多文档界面,用鼠标点击主窗口右顶上方的关闭按扭显示提示信息,例如;"你确实要关闭该窗口吗"这样信息,确定关闭后又显示
- 想写个程序,通过insert,update,delete对数据库产生压力(就是让数据库负荷加大,服务器CPU,内存,IO等利用率加大),用多线程如何?
- 三本.NET经典书籍低价转让,从速(上海地区)
- PDA的listview 的问题
- .net 初次安装问题
- 请问如何获取字符串里特定字节,马上给分,谢谢,
- 请教一下异步连接函数中的参数问题
- 求助
- 讨厌的文件夹自动生成命名空间功能怎么关闭
{
if (Input())
{
UserCheck();
}
登陆语句
int result = (int)cmd.ExecuteScalar();
---------------
这个结果无论神马时候都返回1啊
应该改成select * from Admin where LoginId={0} and LoginPwd={1}
{
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();
}
}
提示出错,并非所有的代码路径都有返回值! 哪出错了?
{
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;
}