So my problem is when I do the initial add record the program I am making automatically skips the first which is ID 1 and starts adding like so 2, 3, 4, 5, 6.
here is my code:
Dim i As Integer = 0
I += 1
Try
Dim sqlcon As New SqlConnection("mysqlstring")
Dim sqladapt = New SqlDataAdapter("Select * from [Table]", sqlcon)
sqlcon.Open()
Dim cmd As SqlClient.SqlCommand
Dim sql As String = "insert into [Table] values(@ID,@Question,@Answers,@Howtowork,@Chapter)"
cmd = New SqlClient.SqlCommand(sql, sqlcon)
' Make sure that all tables have the same type of information that can be entered, if not you will recieve an error.
cmd.Parameters.AddWithValue("@ID", DataGridView1.Rows.Count + I)
cmd.Parameters.AddWithValue("@Question", TextBox2.Text)
cmd.Parameters.AddWithValue("@Answers", TextBox3.Text)
cmd.Parameters.AddWithValue("@Howtowork", TextBox4.Text)
cmd.Parameters.AddWithValue("@Chapter", TextBox5.Text)
cmd.ExecuteNonQuery()
sqlcon.Close()
MessageBox.Show("New Record Added")
Catch ex As Exception
End Try
I figured that it's probably an easy fix that I am not seeing. All I am trying to do is add to the ID unique column using increments of 1. my database must start with 1 and go from there.
What I have tried:
So I tried to put in the first record by just adding it to the table manually before the start of my debugging. This is what happens 1, 3, 4, 5, 6. no matter where I try to start a record it always skips one and after the skip its fine.