LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you set the status variable for a column in a database using SQL toolkit

I'm trying to write to a database (MS SQL Server 2000) using CVI.  When I create a record and use DBPutRecord, I get an error because my primary key cannot accept a "NULL" value.  I understand from the function panel for DBPutRecord that I should set the status variable to DB_NO_DATA_CHANGE (because the primary key is read-only) however, I am unsuccessful in finding a viable way to do this.   I assumed I could do it using the DBMapCol but I still receive errors.  I also tried using DBSetColumnAttribute, but get an error ("Invalid Statement or connection handle").  The handle is correct and I'm not aware of any problem with the statement (seems pretty straighforward.)  Any suggestions for setting the status variable for my primary key column would be greatly appreciated!
0 Kudos
Message 1 of 2
(2,969 Views)
Hello LBurke,

Here is a sample code to set the status variable to DB_NO_DATA_CHANGE.

hmap = DBBeginMap (hdbc);
resCode = DBMapColumnToInt (hmap, "field1", &field1, &field1Stat);
resCode = DBMapColumnToInt (hmap, "field2", &field2, &field2Stat);
resCode = DBMapColumnToInt (hmap, "thecount", &counter, &counterStat);
hstmt = DBActivateMap (hmap, "hascount");
while ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS) {
           field1++; field2++;
           /* set the status variable for the read only column to -9, which is equivalent to DB_NO_DATA_CHANGE */
           /* this indicates that the column should not be updated */
           counterStat = -9;
           /* copy the updated record back to the database */
           resCode = DBPutRecord (hstmt);
}
resCode = DBDeactivateMap (hmap);
if (resCode != DB_SUCCESS) {
          ShowError();
          goto Error;
}


Let me know if you still get errors and the type of errors you get.

Thank you and good luck!
Shakhina P.
Applications Engineer
National Instruments

0 Kudos
Message 2 of 2
(2,954 Views)