If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > how to insert a null-value using SQLBindParameter

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-03, 08:14
fidofox fidofox is offline
Registered User
 
Join Date: Jan 2003
Posts: 17
Unhappy how to insert a null-value using SQLBindParameter

hi,

i got difficulties inserting a NULL-value into my table:
to tell ODBC, that i want to insert a NULL-value, i use a variable (SQLINTEGER) with a value of SQL_NULL_DATA as last argument to SQLBindParameter:

buffer = new char[255];
strcpy(buffer,"");
SQLINTEGER nInd = SQL_NO_DATA;
SQLPrepare(myHandle,"INSERT INTO TEST (col1) VALUES(?)",SQL_NTS);
SQLBindParameter(myHandle,firstcolumn, SQL_PARAM_INPUT, SQL_C_CHAR,SQL_VARCHAR, 0,0, (void*)buffer, 0, &nInd);
SQLExecute(myHandle);

when i call execute a get an access violation

any idea ?
Reply With Quote
  #2 (permalink)  
Old 04-08-03, 13:58
fidofox fidofox is offline
Registered User
 
Join Date: Jan 2003
Posts: 17
Cool Re: how to insert a null-value using SQLBindParameter

solution:
1. the length values have to be at least 1 (don't ask me why) otherwise you get an adequate error message.
2. nInd has to be a pointer to SQLINTEGER at least SQLINTEGER[8];

why ? i don't know.

SQLINTEGER nInd[8];
*(SQLINTEGER*)nInd = SQL_NULL_DATA;
SQLBindParameter(myHandle,firstcolumn, SQL_PARAM_INPUT, SQL_C_CHAR,SQL_VARCHAR, 1,0, (void*)buffer, 1, nInd);

i red at least 20 documentations about SQLBindParameter and didn't find a solution. try and error led to the solution - thanks to Bill - the documentations of microsoft give more confusion than help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On