Writing empty string to SQL Server table using Db-Library
From: Uday Eyunni (post2_at_newsgroup.com)
Date: 06/21/04
- Next message: KarlShifflett: "Lookup Tables (use 1 table or 250)"
- Previous message: Hugo Kornelis: "Re: need help to create query"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 21 Jun 2004 11:48:47 -0700
Hello,
I am experiencing problems in writing empty strings (initialized to "") to
SQL Server (2000) using Db-Library. The following example illustrates what I
am trying to do.
Let's say there are three varchar fields in a table. When the data is
populated to the table only one of the columns will have the data.
Binding of the variables -
DBCHAR val1[11];
DBCHAR val2[15];
DBCHAR val3[13];
if(bcp_bind(dbproc, (LPCBYTE) val1, 0, -1, (LPCBYTE) "", 1, 0, 1) ==
FAIL)
iDbBindCols = false;
if(bcp_bind(dbproc, (LPCBYTE) val2, 0, -1, (LPCBYTE) "", 1, 0, 2) ==
FAIL)
iDbBindCols = false;
if(bcp_bind(dbproc, (LPCBYTE) val3, 0, -1, (LPCBYTE) "", 1, 0, 3) ==
FAIL)
iDbBindCols = false;
// Fill the variables
...
if (bcp_sendrow(dbproc) == FAIL)
sendError = true;
In the above example, if val1 and val2 are initialized to "" and val3
contains the text "John", after calling bcp_sendrow the database table
contains NULL for val1, val2 fields and John for val3 field when you execute
the query from the Query Analyzer.
The table schema doesn't allow NULLs for the columns. So, I am guessing that
columns that hold val1 and val2 might contain '\0'. Also, I can't open the
table using the Enterprise Manager (Open Table -> Return all rows) after
populating the table. The error message "Runtime Error: Data provider or
other service returned an E_FAIL status." is displayed from the enterprise
manager.
Any clues on how to bind the variables to write empty strings to the
database table?
Thanks
- Next message: KarlShifflett: "Lookup Tables (use 1 table or 250)"
- Previous message: Hugo Kornelis: "Re: need help to create query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|