Cannot insert the value NULL into column 'studentId' table ABCISD-TAKS.dbo.StudentInfo'; column does not allow nulls. INSERT fails.

I am trying save a record to a Microsoft SQL 2000 server.  The table has been setup with a primary key for the student Id.  When I try to write data to the table, I get the following error message.

Cannot insert the value NULL into column 'studentId' table FBISD-TAKS.dbo.StudentInfo';
column does not allow nulls.  INSERT fails.

Any help would be appreciated.


Who is Participating?
I think you did not set the Student ID field to autonumber and you are also not inserting the value from the code.

try by setting  the StudentId field to autonumber data type. else change youy insert code to include the Student Id
Please post the code you are using to perform the INSERT
Primary Key fields do not allow a null value and are required for the row to be inserted.
Can u send the exact command which u used to create the table?
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

kwh3856Author Commented:
Here is the code.  I have also verified the studentId does have a value.  What I can not understand is I am not even writing that field and it is giving that error message.

                'Insert Records into StudentInfo
                Dim objConnection7 As SqlConnection = New SqlConnection("server=(local);database=FBISD-TAKS;user id=sa;password=pa55word")
                Dim objCommand7 As SqlCommand = New SqlCommand
                objCommand7.Connection = objConnection7
                objCommand7.CommandText = "Insert Into studentInfo " & "(admDate,grade,esc) " & _
                objCommand7.Parameters.Add("@iadmDate", SqlDbType.DateTime, 10).Value = madmDate
                objCommand7.Parameters.Add("@grade", SqlDbType.Int, 4).Value = grade
                objCommand7.Parameters.Add("@esc", SqlDbType.Int, 4).Value = Val(esc)

            Catch ex As Exception

            End Try

kwh3856Author Commented:

You were right on the money.  The table had been setup with a primary key on the student Id.  I had not added that value to be saved to the record yet so consequently the value would be null.  Since the table was set to no null on student Id it would not allow me to save the record.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.