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
Solved

Getting a Field In FoxPro To Accept Null

Posted on 2011-02-28
4
1,437 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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 viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

766 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