Re: SQLBindParameter

From: Brannon Jones (brannonjNOSPAM_at_gmail.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 14:29:25 -0700

The problem is that you are using Unicode string data, and telling ODBC that
the type of data is an ANSI string. So, you get truncation after the first
character.

The fix is easy, instead of SQL_C_CHAR, use SQL_C_WCHAR. Also, for the sake
of efficiency, make sure that you really want to store the Unicode data in
the database as ANSI (SQL_VARCHAR is ANSI). And double check that the
actual type of the parameter is ANSI (varchar). If the actual type of the
parameter is Unicode (nvarchar) then you are going through an extra,
unnecessary, and possibly lossy, conversion (from Unicode -> ANSI ->
Unicode).

Let me know if you have any more questions on this.

Brannon

"rschuchm" <rschuchm@discussions.microsoft.com> wrote in message
news:4906225F-4F6C-4ECB-8483-5698F9E29E1E@microsoft.com...
> I am having trouble with SQLBindParameter when binding a CString to a
> SQL_VARCHAR; also, I am using UniCode. Only the first character of the
value
> gets passed to the stored procedure called by ExecuteSQL.
>
> m_nBufferLength=SQL_NTS;
> retcode = SQLBindParameter(hstmt,1, SQL_PARAM_INPUT_OUTPUT,
> SQL_C_CHAR,SQL_VARCHAR, 32, 0, (SQLPOINTER)((LPCTSTR)m_strVal), 32,
> &m_nBufferLength);
>
> I've also tried using
> retcode = SQLBindParameter(hstmt,1, SQL_PARAM_INPUT_OUTPUT,
> SQL_C_CHAR,SQL_VARCHAR, 32, 0, m_strVal.GetBuffer(), 32,
&m_nBufferLength);
>
> Any suggestions?
> --
> -rose



Relevant Pages

  • Re: Call C DLL from VB.net-problem..array gains 4 bytes!
    ... No, Unicode strings don't, by definition, have a header with the size. ... you're writing code in C++, for example, the only difference between an ANSI ... which take an array of bytes. ... > Remember the DLL declaration... ...
    (microsoft.public.windowsce.app.development)
  • Re: A (mild-mannered) defense of RosAsm Rocks !!!
    ... All functions that have a Unicode ... and ANSI implementation are Unicode first, ... this API is not available in Win9x without the ... Oh by the way the Coward is the asshole that wrote the peice of garbage ...
    (alt.lang.asm)
  • Re: Error 52 Bad file name or number on file read
    ... Sorry Nick but if you're ending up with a mixture of ANSI and Unicode data ... Private Type FILETIME ... Public Function StripNulls(sText As String) As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Did Borland doing well in Q4? Listen to the Earning CC
    ... AS an ANSI application you will need to change all "String" ... declarations to "ANSIString" (and Char to ANSIChar and PChar to ... Only THEN can you start thinking about how Unicode is best ... Even the specifically "ANSI" FS routines do not use ...
    (borland.public.delphi.non-technical)
  • Re: Is there any problems if there are multiple MFC dlls in one pr
    ... It's a good idea to change the ANSI header file:) ... Many third-party DLLs use extern "C" linkages because they want to be usable from C as ... These will definitely Not Play Well with Unicode. ...
    (microsoft.public.vc.mfc)