谁帮我看下这个为什么错了
//。。。。。。。。。。。。。省略
//连接数据库
string xname = namebox.Text;
string xpassword = passwordbox.Text;
SqlConnection tosql = new SqlConnection("Data Source=.;Initial Catalog=da1;Integrated Security=True");
tosql.Open();
string str = "select * from test where name =" + xname + "and password =" + xpassword;
SqlCommand sql_cmd = new SqlCommand(str,tosql);
SqlDataReader result = sql_cmd.ExecuteReader();
if (result.Read())
{
MessageBox.Show("登陆成功!");
}
else
{
MessageBox.Show("登陆失败!");
}
tosql.Close();
result.Close();
//。。。。。。。。。。。。。省略
------解决方案--------------------什么错误???
------解决方案--------------------查询语句拼接错误,字符串必须用单引号包含起来
string str = "select * from test where name =" + xname + "and password =" + xpassword;
修改为
string str = "select * from test where name ='" + xname + "' and password ='" + xpassword+"'";