?
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
?
576 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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