Click to See Complete Forum and Search --> : Unable to insert into database


Ebola
03-21-2007, 06:24 AM
When I run the form I've made the information is supposed to be sent to a database, there are at least 5-6 other forms doing the exact same thing on my site but this one is giving me an error and I cannot figure out why.

When I run the page itself I get no error, it continues on as if there was no problem, when I go into SQL Server Enterprise Manager and try to manually run a query I get this error: "Cannot insert explicit value for identity column in table 'UpgradeRequests' when IDENTITY_INSERT is set to OFF."

There are 13 fields in my database, the first being the IDNumber, I try to insert 12 fields (Of course letting the identity column fill itself) but it will not let me. The SQL Server Manager changed my query below into this, which might help, it always adds the dbo.tablename without causing any problems at all:

Mine: INSERT INTO UpgradeRequests VALUES('Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing')

"INSERT INTO dbo.UpgradeRequests
(IDNumber , FirstName , LastName , Address , City , State , Zip , EPhone , Email , Product , PurchaseDate , Retailer)
VALUES ('Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing')"

Now, there is another field after retailer, that being SerialNumber, it seems the table is forcing itself into the first field even though it's the primary identity and I have no idea why. The only difference between this table and every other working one is that the identity seed starts at 2000 instead of 1, that's it.

Can anyone help me out here? I'm in kind of a hurry to get this working ASAP.

Edit: The primary column is also an int in case anyone was thinking that's the problem.

Jeff Carr
03-21-2007, 02:01 PM
Seems like

"INSERT INTO dbo.UpgradeRequests
(FirstName , LastName , Address , City , State , Zip , EPhone , Email , Product , PurchaseDate , Retailer, SerialNumber)
VALUES ('Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing')"

should work just fine.

Znupi
03-21-2007, 03:28 PM
I get this error: "Cannot insert explicit value for identity column in table 'UpgradeRequests' when IDENTITY_INSERT is set to OFF."

Your problem is clear (I think). You need to escape your table's name using backquotes (`), like this: INSERT INTO `bdo.UpgradeRequests` ...

Hope this helps.

Ebola
03-21-2007, 11:39 PM
Seems like

"INSERT INTO dbo.UpgradeRequests
(FirstName , LastName , Address , City , State , Zip , EPhone , Email , Product , PurchaseDate , Retailer, SerialNumber)
VALUES ('Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing', 'Testing')"

should work just fine.

That did it, it's working fine now. Thanks alot.