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();
I am having the above query which returns number of rows, now my problem is how t read the output of the query? What i want is
if(count=0)
{
//Do
}
else if(counnt >0)
{
//Do something else
}
You want to use ExecuteScalar();
instead which will return a single result.
So this line:
ddlistCmd.ExecuteReader();
should be:
ddlistCmd.ExecuteScalar();
which you can then assign to count
after type casting the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With