Generating Record ID Key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to insert data from a dataset into the source database. I get an
error when calling update on the data adapter. Here is the error:

Cannot insert the value NULL into column 'KeyID', table 'dbo.Reservations';
column does not allow nulls. INSERT fails.

KeyID is an autogenerated number in SQL Server.

Thanks, Justin.
 
May be you could list out the insert statement, if you don't mind, and also
your table structure, so that anybody else could help,
t
 
Justin,

You must not specify autogenerated number columns in insert statements.

Eliyahu
 
Here is the Insert statement I am using:

this.sqlInsertCommand1.CommandText = @"SET IDENTITY_INSERT Reservations ON
INSERT INTO Reservations(KeyID, EventID, Email, qntyChild, qntyAdult,
qntySenior, GroupID, Status) VALUES (@Identity, @EventID, @Email, @qntyChild,
@qntyAdult, @qntySenior, @GroupID, @Status); SELECT KeyID, EventID, Email,
qntyChild, qntyAdult, qntySenior, GroupID, Status FROM Reservations WHERE
(KeyID = @IDENTITY)";
 
Let me make a wild guess here, your @Identity is no associate to an
appropriate value.

wei chung
 
Back
Top