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
561 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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