“System.Data.SqlClient.SqlException”类型的未经处理的异常在 System.Data.dll 中发生

purple128 2017-01-09 04:25:47
本人新手一个 刚刚入学c# 写的一个连接sql登录界面,为什么启动后登录时就出现下面红色代码错误。终止运行了
SqlConnection conn = db.Camcon();

SqlCommand cmd = new SqlCommand("select coun(*) from register where id='" + textBox1.Text + "'and pwd='" + textBox2.Text + "'", conn);
conn.Open();
int a = Convert.ToInt32(cmd.ExecuteScalar());
if (a >0)
{
conn.Close();
MessageBox.Show("登录成功", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("用户名或密码错误", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
...全文
235 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
purple128 2017-01-09
  • 打赏
  • 举报
回复
谢谢
夏天的枫 2017-01-09
  • 打赏
  • 举报
回复
引用 4 楼 lovelj2012 的回复:
3、该敲空格的敲空格,否则有可能导致语句不能执行滴
select count(*) from register where id='" + textBox1.Text + "' and pwd='" + textBox2.Text + "'"
对头,空格很重要!(上学的时候印象深刻!)
江南小鱼 2017-01-09
  • 打赏
  • 举报
回复
3、该敲空格的敲空格,否则有可能导致语句不能执行滴
select count(*) from register where id='" + textBox1.Text + "' and pwd='" + textBox2.Text + "'"
江南小鱼 2017-01-09
  • 打赏
  • 举报
回复
2、把count写正确,如果还抛出异常,把Camcon方法的代码贴出来
江南小鱼 2017-01-09
  • 打赏
  • 举报
回复
1、你的SQL语句有问题coun(*) ,少一个t,应该是count(*)
shoppo0505 2017-01-09
  • 打赏
  • 举报
回复
你还没定义connection string 呢

111,097

社区成员

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

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

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