Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot Insert Value NULL IN Column
Message
From
20/05/2018 14:36:48
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01660168
Message ID:
01660197
Views:
53
>To all,
>
>Back again! From one issue to another but you're help has moved me forward.
>
>I created a Table in SQL Server 2012 with a character field set to "Not NULL". NULLs have been giving me issues in searching. I get and error: 'Cannot Insert Value NULL IN Column field cSteinLoc. Column does not allow NULLs.' I checked to see what SET NULL is in VFP and it is OFF. It seems to be trying to Insert a NULL value into fields. Even when I use a default of ' ', it still inserts the NULL???
>
>Does anyone know why this is happening and how I can prevent VFP from placing NULLs in empty fields when creating a new record?
>
>Thanks,
>
>Bill

To avoid this error it is best to specify a default value for all columns. In my table definitions I put an empty default value for each data type, for instance '' for Character and Text, 0 for any numeric types, 1900-1-1 for date fields etc.

Here the best practice would be to give a name to the constraint, so you know the name in case you need to programmatically manipulate the field.

ALTER TABLE Tablexxx ADD Fieldxxx Character(10) NOT NULL CONSTRAINT df_Tablexxx_Fieldxxx DEFAULT ''

The other alternative is to allow Nulls, with the added complexity that you describe, or to always mention all fields in inserts, which means you need to alter your code each time the table structure changes at the server where you insert rows. Also very problematic if you have tables that have more than 20 columns.
Christian Isberner
Software Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform