Solved

Getting a Field In FoxPro To Accept Null

Posted on 2011-02-28
4
1,412 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:DPottsLM
  • 2
4 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 34999030
0
 
LVL 41

Expert Comment

by:pcelba
ID: 34999114
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.

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35005758
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.
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 250 total points
ID: 35005783
Hm

another thing: If you do this you get a non nullable field
Create Cursor curTest (int I default null, cText C(10))
Insert into curTest (cText) Values ('test')

Open in new window


Yes, in regard of nullable the default is NOT, setting the default value to null does not automatically make the field nullable, so this needs to be explicitly set in the table designer or in code:
Create Cursor curTest (int I null default null, cText C(10))
Insert into curTest (cText) Values ('test')

Open in new window

This way the field is nullable and get's null if skipped in an insert.

Bye, Olaf.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data center mess 4 81
Error when loading the database 16 64
Foxpro errors 4 32
T-SQL Default value in Select? 5 27
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

777 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