|
Subject:
|
INSERT Fails
|
|
Posted By:
|
teddyk
|
Post Date:
|
7/18/2008 1:31:02 AM
|
Im a student in south africa.I've set a primary key field to (int) data type but when im trying to insert a column it displays a message Like:"Cannot insert the value NULL into column 'VisitorId', table 'F:\LEX DIAMONDS\APP_DATA\DIARYDB.MDF.dbo.tblVisitor'; column does not allow nulls. INSERT fails."
supertedz
|
|
Reply By:
|
robzyc
|
Reply Date:
|
7/18/2008 2:50:01 AM
|
Is this a question or a statement? 
If its a "this is my problem, can someone please help fix it" - then the error message is giving you all the information you need.
When adding a record, any required data must be set. You cannot have a null ID column, since, well, how do you ID something if its ID isn't set? It does not make sense!
Ensure you are setting the ID value for the record when inserting. You can do this a number of ways, use a GUID, increment based on the last used ID, create an ID based on the culmanation of various values etc..
What to use for an ID is always a hot topic of debate so I won't go there! 
Rob http://cantgrokwontgrok.blogspot.com
|
|
Reply By:
|
teddyk
|
Reply Date:
|
7/23/2008 8:56:04 AM
|
hi there thanx 4 your words of a experienced programmer i got it right it was just a matter of setting a key. Ooh, Thanx man. :-)
quote: Originally posted by robzyc
Is this a question or a statement? 
If its a "this is my problem, can someone please help fix it" - then the error message is giving you all the information you need.
When adding a record, any required data must be set. You cannot have a null ID column, since, well, how do you ID something if its ID isn't set? It does not make sense!
Ensure you are setting the ID value for the record when inserting. You can do this a number of ways, use a GUID, increment based on the last used ID, create an ID based on the culmanation of various values etc..
What to use for an ID is always a hot topic of debate so I won't go there! 
Rob http://cantgrokwontgrok.blogspot.com
supertedz
|
|
Reply By:
|
robzyc
|
Reply Date:
|
7/23/2008 8:58:24 AM
|
No problem, happy to help  Always listen to the compiler, it can often be telling you exactly what you need to know 
Rob http://cantgrokwontgrok.blogspot.com
|