Friday, February 24, 2012

Cannot insert the value NULL into column 'ID', table

I am new with SQL and have been using Access. Now with Access, when I
enter in a record, the ID field (which is my primary key) is
automatically incremented.
I am thinking from the error it is not doing that here, is there
something I am missing? (probably a lot)
Chuck
Can you show us your INSERT statement? For a column with the IDENTITY attribute, you don't list the
column in the column name list, and you obviously don't specify a value for it either. Simplified
example:
CREATE TABLE t(c1 int IDENTITY, c2 char(5))
INSERT INTO t(c2)
VALUES('Hello')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<cvillard@.gmail.com> wrote in message news:1124228310.779917.26320@.o13g2000cwo.googlegro ups.com...
>I am new with SQL and have been using Access. Now with Access, when I
> enter in a record, the ID field (which is my primary key) is
> automatically incremented.
> I am thinking from the error it is not doing that here, is there
> something I am missing? (probably a lot)
> Chuck
>
|||This is a sample of my code... am I doing something wierd? Looks
different.
if Request.Form("Action") = "add" then
if Request.Form("txtPassword") = Request.Form("txtConfirm") then
rs.open "SELECT * FROM Users", conn, 1, 3
rs.AddNew
rs("Username") = Request.Form("txtUsername")
rs("Password") = Request.Form("txtPassword")
rs("Email_Address") = Request.Form("txtEmailAddress")
if Request.Form("cbRights") = true then
rs("User_Rights") = "Adminstrator"
else
rs("User_Rights") = "User"
end if
rs("Name") = Request.Form("txtName")
rs("Create_Date") = Date()
rs.Update
Response.Write("<p align='center'><b>The User Profile for " &
rs("Name") & " has been added.</b></p>")
Response.Write("<p align='center'>The user will receive an email
with the account details shortly.</p>")
Response.Write("<p align='center'><input type='button' value='Close
Window' onClick='javascript:window.close()'></p>")
|||Odd. When I went back in the server didnt have Identity setup for the
ID field. Now it seems to be working.

No comments:

Post a Comment