LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert NULL into DB with Database Connectivity Toolkit

Hi all.


I'm trying to insert several 'NULL' values into a DB table using DB TOOLS INSERT DATA from Database Connectivity Toolkit. I've designed the DB so that this three fields are foreign-keys, but they're also allowed to be 'NULL' values. I don't have much experience with DBs, but I think this isn't a mistake since it's been working for a long time.


My problem comes when I try to insert 'NULL' values into these fields (see attached picture). I use DB TOOLS NULL for this.Insert NULL.png

 

I get the following error:
"The INSERT statement conflicted with the FOREIGN KEY constraint ..."

Could you please help me?


Thanks in advance,

Francisco

0 Kudos
Message 1 of 25
(5,577 Views)

Your combined keys must be unique.  So, if you set all three to NULL, you can't do it again.  If you set one to a value, such 123, NULL, NULL, you can't repeat that combination again.  Your problem is not with trying to insert null values, but the deisgn of your database.

0 Kudos
Message 2 of 25
(5,561 Views)

Most probably Value1 is the key. Simply wiring it to a loop counter wont help as you'll start over from 0 the next time the program is run.

There is 2 easy solutions:

1 - change the database to allow duplicates (often not an option)

2 - make Value an autonumbered field (or add such a field)

3 - Read out the highest Value in the table and work from there.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 25
(5,559 Views)

Thanks for your replies, but, I don't understand you clearly.


Attached you can see a view of the table. Those values were inserted with other DB software and there was no problem. Column2 can be NULL as well (despite it's not shown). The primary key of the table is another column I didn't include in this snapshot to make it clearer. It has identity specification. And, as far as I know, there's no need to introduce any value to the primary key field, as it'll be completed by the DB itself.

 

Insert NULL into DB.png

0 Kudos
Message 4 of 25
(5,550 Views)

Then it's a contraint limitation. One of the fields dosn't allow Null. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 25
(5,538 Views)

I don't think that's the problem. Attached you can see the design view of the table.

 

DesignView.png

0 Kudos
Message 6 of 25
(5,533 Views)

Hi,

 

To insert the null character into the Database, You must use the Insert query. In insert query you just pass the null character. The database property itself save the blank value as a "NULL" character.

 

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
0 Kudos
Message 7 of 25
(5,525 Views)

Hi, Himanshu Goyal.

 

What do you mean with "Insert query"?, making a SQL query with the following VI?

 

DB Tools Execute Query.PNG

Thanks.

 

0 Kudos
Message 8 of 25
(5,519 Views)

@Porras wrote:

I don't think that's the problem. Attached you can see the design view of the table.

 

DesignView.png


You're not allowed to enter Nulls into Column1. Nor Column5.

If the string in Column5 is empty, doesn't it get translated to Null?

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 25
(5,514 Views)

But I'm not inserting an empty value in column5. You can see in the first picture I attached that the inserted value is a string called "Value5" (and it isn't empty, I've just tried it). I only try to insert NULL values into columns 2, 3 and 4, the ones where NULL values are allowed, as you can see in the design view.

0 Kudos
Message 10 of 25
(5,506 Views)