LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Toolkit - The field/column contains null

Hello, 

 

I'm getting an error when trying to read an empty field in my database.

The problem apprear when reading the filed 9 and 10. But not with the fields 5 and 6. I copied the columns 5 and 6 to create columns 9 and 10. I changed the title of these columns of course. 

All fields of these column are empty when executing my code. I should get an empty string as field 5 and 6, but when arriving to the filed 9 :

DBGetColChar (iHstmt, 9, &tcCode, "");   //Column 9

I get this error message : 

 

 

NON-FATAL RUN-TIME ERROR:   "DB.c", line 2655, col 9, thread id 0x00001F40:   Function DBGetColChar: (return value == -2 [0xfffffffe]). The field/column contains null.

 

 

Here is my code : 

 

....
iHstmt = DBActivateSQL (tiConnectionHandle[iConnectionBase], tcMessage);   
l_NumberOfRecords = DBNumberOfRecords(iHstmt);
   
   for(int recLoop = 0; recLoop < l_NumberOfRecords; recLoop++)
   {
	    if( DBFetchNext (iHstmt) != DB_SUCCESS) break;
..............

// Get field 5 DBGetColChar (iHstmt, 5, &tcCode, ""); //Column 5 l_s_Alias.name = (char*) malloc(strlen(tcCode)+1); strcpy(l_s_Alias.name,tcCode); DBFree(tcCode); // Get field 6 DBGetColChar (iHstmt, 6, &tcCode, ""); //Column 6 l_s_Alias.name = (char*) malloc(strlen(tcCode)+1); strcpy(l_s_Alias.name,tcCode); DBFree(tcCode); // Get field 9 DBGetColChar (iHstmt, 9, &tcCode, ""); //Column 9 l_s_Alias.name = (char*) malloc(strlen(tcCode)+1); strcpy(l_s_Alias.name,tcCode); DBFree(tcCode); // Get field 10 DBGetColChar (iHstmt, 10, &tcCode, ""); //Column 10 l_s_Alias.name = (char*) malloc(strlen(tcCode)+1); strcpy(l_s_Alias.name,tcCode); DBFree(tcCode); } DBDeactivateSQL(iHstmt); ...

I checked the Default value of all fields in my Access DB, it's an empty string : ""

 

Any idea to solve this problem please ? 

 

Regards,

Blue

 

0 Kudos
Message 1 of 3
(4,054 Views)

Hi Houssam_AZ,

 

 

You mentioned that you are copying fields 9 and 10 from fields 5 and 6. Are you explicitly setting initial values for fields 9 and 10 when declaring them? Also, try setting the strings to non-empty values before attempting to access them, to see whether this clears the error.

Tom D.
Staff Software Engineer
NI
0 Kudos
Message 2 of 3
(4,007 Views)

Hi,

the error message says that the column contains NULL, and you should pay attention that in SQL an empty string "" is different from the special value "NULL"

Are you sure that the column contain an empty string "" and not a NULL?

 

To handle "NULL" parameters and column you must use the variant data in SQL toolkit.

For example DBGetColVariant()

 

Variant are a little bit more complicated that standard data types, but they're much more powerful.

You need to learn how to work with variant and this requires some time, but I think you can solve your issue in this way

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
Message 3 of 3
(3,927 Views)