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(); }
SELECT IDENT_CURRENT('Item')
txtItemID.Text = Convert.ToString(dt.Rows[0]["ItemID"]);
private void BindItemID() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mydb"].ConnectionString); string sItemID = string.Empty; try { con.Open(); SqlCommand cmd = new SqlCommand("Select max(ItemID)+1 from Item", con); SqlDataAdapter da = new SqlDataAdapter(cmd); sItemID = Convert.ToString(cmd.ExecuteScalar()); txtItemID.Text = sItemID.ToString().Trim(); } catch (Exception ex) { } finally { con.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)