Fetch Id from database and Show it on Label

Dotnet4ashu
Posted by Dotnet4ashu under ASP.NET category on | Points: 40 | Views : 1137
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlCommand cmd;
public void BtnCount_Click(object sender, EventArgs e)
{
val();

}
public void val()
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
try
{
int i = 0;
string s = null;
s = ("select count(*) from products");
con.Open();
cmd = new SqlCommand(s, con);
cmd.Parameters.AddWithValue("@CategoryId", lblcount.Text);
da = new SqlDataAdapter(cmd);
da.Fill(ds);
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
lblcount.Text = ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();
}
cmd.ExecuteNonQuery();
con.Close();



}
catch (Exception ex)
{
Response.Write(ex);
}
finally
{

}

}

Comments or Responses

Login to post response