6
Answers

Error in Auto increment ID in C#?

Sakthis

Sakthis

11y
1.5k
1
I am success while increment the id 1 to 10 after that  it can't  increment, i mean after the 10 while i increment the id it comes 10 only again and again and stored multiple 10 in sql table? i dont know how to resolve it can anyone? 

Here enclosed my code :

  private void btnAutoID_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection("Data Source=sakthi\\sqlexpress; Initial Catalog=LoginDetails; Integrated Security=True;");
            SqlCommand sqlcmd = new SqlCommand("select isnull(max(empcode), 0) from emp", sqlcon);
            {
                sqlcon.Open();
                object obj = sqlcmd.ExecuteScalar();
                sqlcon.Close();
                txtEmpCode.Text = (int.Parse(obj.ToString()) + 1).ToString();
            }
        }
Answers (6)