Renjith V S

Renjith V S

  • NA
  • 317
  • 66.3k

Populate sql data value to text box in asp .net?

Apr 1 2014 5:10 AM
Hi,
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();                
}
 

Answers (2)