帅哥回答:web service端为什么无返回值?

safinxia 2002-12-01 03:05:32

string sql="SELECT Tb_students.Stunum FROM Tb_students WHERE Stunum = "+"'"+num+"'"+" AND "+"Stupassword='"+password+"'";

sqlConnection1.Open();

System.Data.SqlClient.SqlCommand command=new SqlCommand(sql,sqlConnection1);

int count=command.ExecuteNonQuery();//执行到这里的时候就挂了,ExecuteNonQuery()执行不下去了,count 没有返回值!

请高手指点,很急啊!
...全文
42 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmmgmm 2002-12-01
  • 打赏
  • 举报
回复
ExecuteNonQuery() 不返回任何值

ExecuteScalar() 返回第一组结果集的第一个查询字段值,而且必须拆箱

此外,推荐楼主使用Parameter填充的形式而不是连接字符串的形式:

string sql = "SELECT Tb_students.Stunum FROM Tb_students WHERE Stunum = @num AND Stupassword = @password";
System.Data.SqlClient.SqlCommand command = new SqlCommand(sql,sqlConnection1);
command.Parameters.Add("@num",num);
command.Parameters.Add("@password",password);
int count=(int)command.ExecuteScalar();
yarshray 2002-12-01
  • 打赏
  • 举报
回复
int count=(int)command.ExecuteScalar();
luhanzhang 2002-12-01
  • 打赏
  • 举报
回复
改为:
int count=(int)command.ExecuteNonQuery();//count是command数据库表中受影响的行数

110,534

社区成员

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

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

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