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 NayakRank #47 · 31.5K reputationPosted Apr 3, 2013, 11:28 PM EDT
con.Open();
str = "select count(name)from table";
com = new SqlCommand(str, con);
txt_count.Text = com.ExecuteScalar().ToString();
con.Close();
Vishal GilbileRank #268 · 9.4K reputationPosted Apr 3, 2013, 11:00 PM EDT
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.
Kunal VaishyaRank #990 · 2K reputationPosted Apr 4, 2013, 2:23 AM EDT