the below coding getting execute but the value was not printing in screen
protected void Button1_Click(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
string OIMSquery = "SELECT COUNT(name) AS PolicySold FROM TestDate WHERE name='divi'";
SqlCommand OIMScmd = new SqlCommand(OIMSquery, OIMS_01);
OIMS_01.Open();
OIMScmd.ExecuteNonQuery();
OIMS_01.Close();
}
}
Satyapriya NayakPosted Apr 4, 2013, 3:28 AM
con.Open();
str = "select count(name)from table";
com = new SqlCommand(str, con);
txt_count.Text = com.ExecuteScalar().ToString();
con.Close();
Kunal VaishyaPosted Apr 4, 2013, 6:23 AM
Vishal GilbilePosted Apr 4, 2013, 3:00 AM
Instead of using ExecuteNonQuery method try making use of ExecuteScalar();. Just change the below line
OIMScmd.ExecuteNonQuery();
With the following line
OIMScmd.ExecuteScalar();
Hope that solves your problem.
With Regards,
Vishal Gilbile.