Solved

Getting a Field In FoxPro To Accept Null

Posted on 2011-02-28
4
1,527 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
[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
4 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 34999030
0
 
LVL 42

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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 …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

689 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