SqlDataAdapter primary key update issue

Hi:
I'm new to this & am havin a issue updated my data through a sqldataadapter.
I have no problem deleting & modifing my info
When I try to insert the information the user has provided & generate a primary key, I get the following error:
Cannot insert the value NULL into column 'id', table tlbOrder ; column does not allow nulls. INSERT fails.

Dim conn As SqlConnection = GetSQLConnection()
Try
Dim sql As String = "Select * from tblOrder"
Dim sa2 As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Try
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(sa2)
If ds.HasChanges Then
sa2.Update(ds, "tblOrder")
ds.AcceptChanges()
End If
Finally
sa2.Dispose()
End Try

Finally
conn.Close()
conn.Dispose()
End Try

I thought this worked the same way as the insertcommand & my key was generated when I used this before to get my id.
Dim sql As String = "Select * from tblOrder where id = -1"

Please send me in the correct direction..
thank you

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories