我正在尝试存储查询字符串的结果
q = "select count(*) from test" (asp.net c#)
在一个字符串变量中,这样我就可以在点击按钮时显示标签上的计数。
答案 0 :(得分:5)
int RecordCount;
RecordCount = Convert.ToInt32(cmd.ExecuteScalar());
string myString = RecordCount.ToString();
答案 1 :(得分:1)
ExecuteScalar can be null的值,请确保检查为空
int RecordCount = 0;
object retVal = cmd.ExecuteScalar();
if(retVal != null)
RecordCount = Convert.ToInt32(cmd.ExecuteScalar());