how to get the next autoincrement value in sql

后端 未结 10 960
时光取名叫无心
时光取名叫无心 2020-12-16 13:21

I am creating a winform application in c#.and using sql database.

I have one table, employee_master, which has columns like Id, name, address

10条回答
  •  伪装坚强ぢ
    2020-12-16 13:36

     SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=databasename;User ID=sa;Password=123");
     con.Open();
     SqlCommand cmd = new SqlCommand("SELECT TOP(1) UID FROM InvoiceDetails ORDER BY 1 DESC", con);
    
     SqlDataReader reader = cmd.ExecuteReader();
    
     //won't need a while since it will only retrieve one row
     while (reader.Read())
     {
         string data = reader["UID"].ToString();
         //txtuniqueno.Text = data;
         //here is your data
         //cal();
         //txtuniqueno.Text = data.ToString();
         int i = Int32.Parse(data);
         i++;
         txtuid.Text = i.ToString();
      }
    

提交回复
热议问题