String dd_webCofig = ConfigurationManager.ConnectionStrings["server132"].ConnectionString;
SqlConnection ddlistconn = new SqlConnection(dd_webCofig);
ddlistconn.Open();
string ddlist = "select count(*) from jud_order where complex_name=@a and case_no=@b and sign=@c and jud_order_date=@d and user_code=@e";
SqlCommand ddlistCmd = new SqlCommand(ddlist, ddlistconn);
ddlistCmd.Parameters.AddWithValue("a", "a");
ddlistCmd.Parameters.AddWithValue("b", "a");
ddlistCmd.Parameters.AddWithValue("c", "a");
ddlistCmd.Parameters.AddWithValue("d", "a");
ddlistCmd.Parameters.AddWithValue("e", "a");
SqlDataReader myReader = ddlistCmd.ExecuteReader();
我有上面的查询,它返回行数,现在我的问题是如何读取查询的输出?
我想要的是
if(count=0)
{
//Do
}
else if(counnt >0)
{
//Do something else
}
最佳答案
您想使用ExecuteScalar();
来代替它,它将返回一个结果。
所以这句话:
ddlistCmd.ExecuteReader();
应该是:
ddlistCmd.ExecuteScalar();
然后可以在键入casting结果后将其分配给
count
。