Previous Thread

8/17/2006 10:49:01 PM    SQLBindParameter & empty strings
Hi, 
 
I was using MySQL before migrating to SQL Server 2005 Express. I didn't have 
 
any problems with SQLBindParameter when binding an SQL_CHAR param whose value 
 
was an empty string, but SQL Server doesn't seem to like it. 
 
At first I had set the ColumnSize to 0 -- which is probably what caused the 
 
HY104 Invalide precision value error. After changing the ColumnSize (say my 
 
column was a varchar(30) and i set columnsize to 30), I didn't get the error 
 
anymore, but I found that the length of the 'data' written into the database 
 
was 30 instead of 0! 
 
How can I get around this problem of an empty string? 
 
Thanks, 
 
Isa



8/18/2006 11:17:35 AM    Re: SQLBindParameter & empty strings
"Isa" <Isa@discussions.microsoft.com> wrote in message 
 
news:1282A15E-7F7C-4E04-A751-D01E996B694B@microsoft.com... 
 
I hope this helps.  My 'normal' function to bind a string  checks 
 
for a string length of zero (empty string).  If that's the case, 
 
it calls NullString() as shown below.  It may just be that your 
 
Length/Indicator parameter has to be set to SQL_NULL_DATA. 
 
void VParameter::NullString( void ) 
 
{ 
 
SQLRETURN rc; 
 
m_LenInd = SQL_NULL_DATA; 
 
rc = SQLBindParameter( m_hStmt, m_paramNumber, 
 
SQL_PARAM_INPUT, 
 
SQL_C_CHAR, SQL_CHAR, 1, 0,  0, 0, (SQLLEN *) 
 
&m_LenInd ); 
 
CHECK_STMT( m_hStmt, rc ); 
 
} 
 
HTH, 
 
- Arnie