I have a text box named txtItemID. An Sql data base table named Item is used. It has the column named ItemID, which is created by using max(ItemID)+1 value. My requirement is whenever the page load occurs(run my page in asp .net), the max(ItemID)+1 value should be shown in the text box txtItemID. I have done these codes but it doesn't works :
private void BindItemID()
{ SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mydb"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Select ItemID from Item", con);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt);
txtItemID.Text = dt.ToString();
txtCode.DataBind();
}

VulpesPosted Apr 1, 2014, 5:37 AM
txtItemID.Text = cmd.ExecuteScalar().ToString();
Renjith V SPosted Apr 1, 2014, 5:57 AM