SqlConnection con = new SqlConnection("server=.;Trusted_Connection=yes;user=sa;pwd=1;database=playerinfo");
con.Open();
SqlCommand cmd = new SqlCommand("select * from player_info where name='"+textBox1.Text+"and pwd="+textBox2.Text+ "'", con);
int state = cmd.ExecuteNonQuery();
con.Close();
if (state == 0)
{
MessageBox.Show("用户不存在,请检测用户名和密码是否正确!");
}
else
{
Form f = new Introduce();
this.Hide();
f.Show();
}
不知道为什么不行 输入错误的时候还是可以登陆呢
解决方案 »
- winForm 里的dataGridView 里数据怎么用文本框来展示
- RichTextBox 中实现段落对齐及其缩进问题
- statusstrip中添加statuslabel时文字无法显示出来?
- 又是窗体传值的问题,大家来看下该怎么写··
- 传值问题高手指点下
- 怎样将DateTimePicker绑定于DataGrid里面啊???
- 求助!MD5问题.
- 【着急ing】用C#怎样读取外部扩展IO的数据阿,basic里用INP90()很容易就实现了:(
- help me!
- 各位学习C#的朋友,能不能留下Msn一块交流!(请版主手下留情!给我们菜鸟一个机会!)
- C# winform 中SaveFileDialog和OpenFileDialog没有响应应,打不开?
- 怎么把AutoCAD嵌入到c# Winform程序的一个窗体中
检查下这个sql 好像有问题
{
MessageBox.Show("用户不存在,请检测用户名和密码是否正确!");
}
else
{
Form f = new Introduce();
this.Hide();
f.Show();
}
con.Close();
con.Open();
SqlCommand cmd = new SqlCommand("select * from player_info where name='"+textBox1.Text+"' and pwd='"+textBox2.Text+ "'", con);//是字符串要加单引号,该有空格的用空格(and前有空格)
int state = cmd.ExecuteNonQuery();//既然是select,不用ExecuteNonQuery,用ExecuteScalar()或者sql语句改成SELECT COUNT(*) FROM player_info where name='"+textBox1.Text+"' and pwd='"+textBox2.Text+ "'
// 参考http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlcommand.executescalar.aspx
con.Close();
if (state == 0)
{
MessageBox.Show("用户不存在,请检测用户名和密码是否正确!");
}
else
{
Form f = new Introduce();
this.Hide();
f.Show();
}