Question : What is wrong with this query?  Counting rows in the db.

I am trying to get a count of the rows,  that contain then name “images2”.  what is wrong with my query.  

My code:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        Object returnValue;

       
        cmd.CommandText = "SELECT COUNT(*) FROM pics WHERE picUrl = 'images2'";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlConnection1;

        sqlConnection1.Open();

        returnValue = cmd.ExecuteReader();

        sqlConnection1.Close();

        Label1.Text = returnValue.ToString();

Answer : What is wrong with this query?  Counting rows in the db.

so it should be

sqlConnection1.Open();

   //    returnValue = cmd.ExecuteScalar();
   //    returnValue = cmd.ExecuteReader();
        SqlDataReader reader = cmd.ExecuteReader();

       

        if (reader.Read())
       {
           Label1.Text = reader[0].toString();
       }

     
       
        sqlConnection1.Close();

Random Solutions  
 
programming4us programming4us