Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I have 1 table that table contain jobs records and cars records

In web page 2 lables, 1 lable display cars count and 2nd lable display jobs count

I write code below:
C#
try
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["masthanConnectionString"].ConnectionString);
            con.Open();
           
            string str = "select count(*) from productdetails where Title='cars'";
            
            SqlCommand cmd = new SqlCommand(str, con);
            //cmd.Parameters.AddWithValue("cmd",con);
            Label1.Text = cmd.ExecuteNonQuery().ToString();
            //cmd.ExecuteNonQuery();
            con.Close();
        }
        catch
        {
            //Label1.Text = "";
        }

but i got output -1

in database total cars count 6 but here display -1 only

please reply me what mistake
and i resolve this
Posted
Updated 16-Feb-14 20:31pm
v2
Comments
member1431 17-Feb-14 2:30am    
Thank you

1 solution

try this

Label1.Text = cmd.ExecuteScalar();
 
Share this answer
 
Comments
member1431 17-Feb-14 2:30am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900