[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
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
Medium Priority
?
592 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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
 

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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

831 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