I am having a problem with trying to create new rows in sql server with a typed data adapter where the primary key is set to GUID and the default value is NewSequentialID()
The column friendInviteID is a GUID and has a default value of NewSequentialID()
Using myDT As New DAL.mbrFriendInvites.mbrFriendInvitesDataTable
Using myTA As New DAL.mbrFriendInvitesTableAdapters.mbrFriendInvitesTableAdapter
Dim row As DAL.mbrFriendInvites.mbrFriendInvitesRow = myDT.NewmbrFriendInvitesRow
With row
.friendInviteID = Nothing
.mbrID = 11
.appID = 2
.contactEmail = "blah@blah.com"
.contactName = "blah blah"
.timesSent = 0
End With
myDT.AddmbrFriendInvitesRow(row)
Dim result As Integer = myTA.Update(myDT)
HttpContext.Current.Response.Write("rows updated: " & result)
End Using
End Using
When I insert a new row using the above method, SQL Server sets the value of friendInviteID to: 00000000-0000-0000-0000-000000000000
It doesn’t seem to want to use the NewSequentialID() default value.
I can manually create a GUID and insert it that way , but that will not create a SequentialID.
What am I missing?
Change your TableAdapter’s
InsertCommandso that it creates the GUID or calls any scalar valued UDF that returns it:Click here for full-view
If you simply want to create a GUID in sql-server – you could also use newid():
You can also use a Stored-Procedure as CommandType of the
InsertCommandthat does that all and returns the actual values via output parameters.I’ve asked myself recently how to retrieve those primary keys: Retrieve identity value from inserted record's primary key
If you need more informations on this issue i’ll have a look how i’ve implemented it. Anyhow you need InputOutput as
Directionfor yourInsertCommand‘s parameters then.