string UserCode = textBox1.Text.Trim();
string UserPswd = textBox2.Text.Trim();
SqlConnection connStr = new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=用户数据库");
string comText = "select top 1 账号 from UserTable where 账号='" + UserCode + "'and 密码='" + UserPswd + "'";
SqlCommand cmd = new SqlCommand(comText, connStr);
//如果数据库已关闭,则打开数据库
if (cmd.Connection.State.ToString() == "Closed")
cmd.Connection.Open();
if (UserCode == "")
{ MessageBox.Show("请输入账号!", "提示"); }
else
{
SqlDataReader sqldr = cmd.ExecuteReader();
//读出查询结果,并判断是否为该用户
if (sqldr.Read())
{
if (sqldr["账号"].ToString() == UserCode)
{
MessageBox.Show("登陆成功!", "消息框");
this.Close();
}
else
{
MessageBox.Show("用户名和密码不相符!", "警告");
}
}
cmd.Connection.Close();
想问一下,身份确定时,程序出错,说红色部分在数据库第一行‘=’有语法错误,怎么回事啊?
请指教!