473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Generating Record ID Key

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.
Nov 18 '05 #1
4 1101
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" wrote:
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.

Nov 18 '05 #2
Justin,

You must not specify autogenerated number columns in insert statements.

Eliyahu

"Justin" <Ju****@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
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.

Nov 18 '05 #3
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)";
"Justin" wrote:
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.

Nov 18 '05 #4
Let me make a wild guess here, your @Identity is no associate to an
appropriate value.

wei chung

"Justin" wrote:
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)";
"Justin" wrote:
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.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin Lebar | last post by:
Sorry about the huge post, but I think this is the amount of information necessary for someone to help me with a good answer. I'm writing a statistical analysis program in ASP.net and MSSQL7 that...
12
by: Martin_Hurst | last post by:
Has some one come up with a similar type script that could be used in a Postgresql database? The script below was created for a SQLServer database. Thx, -Martin ...
6
by: HD | last post by:
Hello. For the following, I would appreciate if anyone could tell me: if it can be done, how it might done, and/or what search terms I could use to find the solution myself. I would like to...
1
by: Dwight | last post by:
Hi all, Iam using Access 2003. I need a field that generates a number for each record, instead of asigning the number to each record (like AutoNumber). I normally use a spreadsheet, such as...
7
by: Mary | last post by:
Hi, I need some assistance with a query. To be honest, I'm not even sure it can be done. I'll try to keep the information limited to only what's relevant to what I have and what I am trying to...
2
by: sugaray | last post by:
I want to write a school computer billing system, one of the function is to distribute machine id using rand() for each student log on, suppose there's 100 machines, when each person log on, the...
8
by: Craig | last post by:
Hi there, I'm only new to Python so please bear with me. I using ElementTree to generate an XML file that will reference a DTD and an XSL file. The header information I want at the start of...
3
by: deciacco | last post by:
I'm trying to write a label printing SDI app with a small preview on the main form itself. Every time I run the InvalidatePreview event on the preview control to redraw the preview I get the...
1
by: shank | last post by:
I'm generating excel spreadsheets online with many manufacturers. One particular manufacturer has 5000 more records than the next highest. When I query for that manuf the table does not form. Just...
3
by: mphil.star | last post by:
I am creating a certain program and in that program i want to add a field which will be creating numbers with text in sequence older " Like MPL 001/08 to unlimited " And 08 be current year. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.