C#关于登陆的问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:12:34
SqlConnection SqlCon = new SqlConnection("server=(local);database=BookManager1;uid=sa;pwd=;");
SqlCon.Open();
string strSql = " select * from User where UserID=' " + textuserid.Text + " ' and UserPassword=' " + textpassword.Text + " ' ";
SqlCommand myCommand = new SqlCommand(strSql, SqlCon);
SqlDataReader read = myCommand.ExecuteReader();
if (read.HasRows==true)
{
MainForm f = new MainForm();
f.Show();
}
else
MessageBox.Show("用户名和密码不正确!");
SqlCon.Close();
}
帮我看看有没有错,调试总说User附近有语法错误

string strSql = " select * from User where UserID=' " + textuserid.Text + " ' and UserPassword=' " + textpassword.Text + " ' ";
user在SQL是关键字
把表名user换成[user]就OK了
string strSql = " select * from [User] where UserID=' " + textuserid.Text + " ' and UserPassword=' " + textpassword.Text + " ' ";

user在SQL中是关键词
应该换为[user]