我只想根据qno字段行是否为空来设置变量,即先前是否插入了任何条目
c#code:
cmd2 = new SqlCommand("Select COUNT(*) FROM " + tname + "WHERE qno = @qno", con99);
cmd2.Parameters.AddWithValue("@qno", qno);
if ((int)cmd2.ExecuteScalar() == 0) //V Studio shows error here
qno_present = 0;
else
qno_present = 1;
错误:
类型' System.Data.SqlClient.SqlException'的异常发生在System.Data.dll中但未在用户代码中处理 附加信息:' ='。
附近的语法不正确答案 0 :(得分:3)
cmd2 = new SqlCommand("Select COUNT(*) FROM " + tname + "WHERE qno = @qno", con99);
在WHERE
子句
cmd2 = new SqlCommand("Select COUNT(*) FROM " + tname + " WHERE qno = @qno", con99);