谁帮我看下这个为什么错了

KIDbody 2014-03-15 06:41:55
//。。。。。。。。。。。。。省略
//连接数据库
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();
//。。。。。。。。。。。。。省略


...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
KIDbody 2014-03-15
  • 打赏
  • 举报
回复
谢了啊!大神
  • 打赏
  • 举报
回复
查询语句拼接错误,字符串必须用单引号包含起来 string str = "select * from test where name =" + xname + "and password =" + xpassword; 修改为
string str = "select * from test where name ='" + xname + "' and password ='" + xpassword+"'";
Regan-lin 2014-03-15
  • 打赏
  • 举报
回复
什么错误???

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧