-5

The case that a column such as the ID column on a table will auto increment. This simply means that the next insert into the table will have an ID that is one more then the previous one and therefore all ID's will be unique.

However, if you delete a row from the table, the table will auto increment as if the row had not been deleted at all. The result is a gap in the sequence of numbers. This is normally not that much of an issue, but you may want to reset the auto increment field.

PatientNo is primary key and here is the code what I have tried so far

    private void txtincr()
    {
        int a;
        if (textPatientNo.Text == "")
        {
            if (con.State == 0)
            {
                con.Open();
            }
            string Query= "select PatientNo from PatientRegistration";
            SQLiteDataAdapter DataAdapter = new SQLiteDataAdapter(Query,con);
            DataSet PatientDataSet = new DataSet();
            DataAdapter.Fill(PatientDataSet);
            if (PatientDataSet.Tables[0].Rows.Count != 0)
            {
                a = PatientDataSet.Tables[0].Rows.Count;
                a = a + 1;
                textPatientNo.Text = Convert.ToString(a);
                textPatientName.Focus();
            }
            else
            {
                textPatientNo.Text = "1";
                textPatientName.Focus();
            }
            con.Close();
        }
    }
BDL
  • 21,052
  • 22
  • 49
  • 55
aman sanghani
  • 21
  • 1
  • 7

2 Answers2

0
You can try using the SQL Query

    DBCC CHECKIDENT('TABLENAME',RESEED,initialvalue);
Manu Nair
  • 314
  • 2
  • 7
0

When you have declared the column as INTEGER PRIMARY KEY, you don't need to do anything because the database automatically uses the next value after the largest value in the table.

When you have declared the column as INTEGER PRIMARY KEY AUTOINCREMENT, the current counter is stored in the sqlite_sequence table. You can simply modify it by updating that table.

Community
  • 1
  • 1
CL.
  • 173,858
  • 17
  • 217
  • 259