-3

我正在尝试存储查询字符串的结果

q = "select count(*) from test" (asp.net c#)

在字符串变量中,以便我可以在按钮单击时在标签上显示计数。

4

2 回答 2

5
    int RecordCount;
    RecordCount = Convert.ToInt32(cmd.ExecuteScalar());
   string myString =  RecordCount.ToString();
于 2012-10-23T16:39:42.847 回答
1

ExecuteScalar的值可以是 null,请确保检查 null

int RecordCount = 0;
object retVal = cmd.ExecuteScalar();
if(retVal != null)
    RecordCount = Convert.ToInt32(cmd.ExecuteScalar());
于 2012-10-23T17:01:02.373 回答