And incidentally, will auto-increment just start incrementing from the highest existing ContactID, or will it first use lesser ContactID values that are absent from the table (presumably due to deletions)?
Also, it will not start at the lowest value (if records are deleted). It will pick up from where it left off, there is no way to "fill in" holes left by deleted records.
Your method for setting the identity is correct.
Are you using a dataset object, or just data tables as an intermediary?
For example, I don't use dataset objects because I make frequent changes to my databases, which require frequent changes to the datasets and can result in much frustration.
I write directly to the database (whereas the dataset requires you to commit the changes made to the dataset before it writes to the database). Could you post a more complete listing of the code?
Manual data insertion (in VB
Dim val1 As String = "test"
Dim val2 As String = "test2"
Dim val3 As String = "test3"
Dim connStr As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("myConnectionStringName").ConnectionString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("INSERT INTO [TABLENAME] (NAME1,NAME2,ETC) VALUES('" & val1 & "','" & val2 & "', '" & val3 & "')",conn)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
if rowsAffected > 0 then
I am leaving work right now, otherwise I would have shown that in c#. Also note that the way I retreive the connection string is consistent with a website, you may or may not be using a website. If not, you connection string is in the application config.
Let me know if that helps, or makes it worse.
Try setting the values for row before adding it to the datatable.