Solved

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

Posted on 2004-09-15
7
558 Views
Last Modified: 2012-05-05
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.

Thanks
Kenny

0
Comment
Question by:kwh3856
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 4

Expert Comment

by:gdexter
ID: 12066503
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.
0
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12066515
Can u send the exact command which u used to create the table?
0
 
LVL 27

Expert Comment

by:planocz
ID: 12066526
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:kwh3856
ID: 12066571
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.



 Try
                '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) " & _
                            "VALUES(@iadmDate,@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)

                objConnection7.Open()
                objCommand7.ExecuteNonQuery().ToString()
                objConnection7.Close()
            Catch ex As Exception
                MsgBox(ex.ToString())

            End Try

0
 
LVL 4

Accepted Solution

by:
Kaarthick earned 500 total points
ID: 12066639
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
0
 
LVL 27

Expert Comment

by:planocz
ID: 12066683
0
 

Author Comment

by:kwh3856
ID: 12066777
Kaarthick,

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.

Thanks
Kenny
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now