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 :
Code
private void BindItemID()Code
{Code
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mydb"].ConnectionString);Code
con.Open();Code
SqlCommand cmd = new SqlCommand("Select ItemID from Item", con);Code
SqlDataAdapter da = new SqlDataAdapter(cmd);Code
DataTable dt = new DataTable();Code
da.Fill(dt);Code
txtItemID.Text = dt.ToString();Code
txtCode.DataBind();Code
}

VulpesRank #55 · 29.2K reputationPosted Apr 1, 2014, 1:37 AM EDT
txtItemID.Text = cmd.ExecuteScalar().ToString();
Renjith V SRank #5,293 · 304 reputationPosted Apr 1, 2014, 1:57 AM EDT