Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nvarchar empty string: " " not ""

Status
Not open for further replies.

intersan

Programmer
Jun 1, 2005
3
US
I am writing a C++ application using ADO to manage an SQL Server dbase.
The database is set to compatibility version 80.
If I set an nvarchar field to an empty string ""; it is stored in the dbase as a
single space string: " ". I need it to be an empty string in the dbase so I can distinguish between an empty string and a single space string.

I am using the SQLOLEDB connector. According to the help that came with SQL Enterprise manager, if the dbase is set to compatibility level 70 or 80 then
"The empty string literal (' ') is interpreted as an empty string."
But it does not to make a difference.

Thanks,
 
Why not try using NULLS, this way there is no compatibily issue.
 
I am not sure how to set a value to null. I am using code like this:

cmdPtr->Parameters->Append(cmdPtr->CreateParameter(bstr_t(m_name), ADODB::adBSTR, ADODB::adParamInput, m_length, parameter->m_variant));

How do I add a NULL parameter?

intersan
 
Check the value you want and try this

<parameter name>.value = IIf(<some string> = "", Convert.DBNull, <some string>)

If the value of the string is "" it will be assigned NULL, other wise it will be set with the strings value.
 
I figured it out. Thanks for the assistance. A helpful link
is


I did the following which works:

m_variant.ChangeType(VT_NULL);
cmdPtr->Parameters->Append(cmdPtr->CreateParameter(bstr_t(m_name), ADODB::adBSTR, ADODB::adParamInput, m_length, m_variant));

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top