我只想看看我的存储过程是否选择了任何行。
using (var conn = new System.Data.SqlClient.SqlConnection(
"Data Source=DANIEL-DATOR;Initial Catalog=EvaluationTest;Integrated Security=True"))
using (var command = new SqlCommand("countRecords", conn))
{
conn.Open();
command.Parameters.Add(new SqlParameter("@usermail", prop.Sendmail));
command.CommandType = CommandType.StoredProcedure;
int userCount = (int)command.ExecuteScalar();
conn.Close();
if (userCount > 0)
{
return 1;
}
return 2;
我从代码中得到这个错误: System.InvalidCastException: Specified cast is not valid。我究竟做错了什么?