Link to home
Start Free TrialLog in
Avatar of DPottsLM
DPottsLM

asked on

Getting a Field In FoxPro To Accept Null

I am trying to do an insert statement into a foxpro database I created.  I need a numeric value to remain empty for processing reasons of another program.  If I leave the field out in my insert query I get an error that says "Field Name does not accept null".  I need to figure out how to get Foxpro to be able to accept a null value.
Avatar of derekkromm
derekkromm
Flag of United States of America image

Avatar of Pavel Celba
If you have FoxPro then you may do this change in IDE which is very easy:

Open the table by USE command, issue MODIFY STRUCTURE, and check the NULL box in appropriate column.

You may also issue following command:

ALTER TABLE YourTable ALTER COLUMN YourColumn NULL

If you don|t have Visual FoxPro IDE the you may issue above command via OLE DB but the table must be open exclusively.

BTW, empty for numeric field means value = 0.  FoxPro also supports BLANK values... NULL is something else than empty or blank in FoxPro and it is probably the best choice.

If you define a field not nullable the behvior you get is a 0 stored into that field, not an error:

Create Cursor curTest (int I not null, cText C(10))
Insert into curTest (cText) Values ('test')

Open in new window


So as far as I see it the error must have another reason than a not nullable field.

If the developer did define the table as follows, you'd have that error indeed:
Create Cursor curTest (int I not null default null, cText C(10))
Insert into curTest (cText) Values ('test')

Open in new window


But that would mean the developer of that database made a logical error, as a not nullable feidl should not have a null default value. The only reason I see is, he wanted to explicitly force a user of the table to insert a non null value, even if that's 0, but that would also be achived, if the field had no default value at all.

So afterall, I'd only be able to tell more, if you specify the exact error you get from which code.

Bye, Olaf.
ASKER CERTIFIED SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial