nvarchar in crecordset

From: Yan (bytj_at_yahoo.com)
Date: 11/02/04


Date: Tue, 2 Nov 2004 15:00:38 -0500

In my "Customers" table, I have some fields in "nvarchar" type. However,
my program always runs into a problem when the field type is "nvarchar".
Other fields with "char" or "varchar" type works fine. My code snippet is
as follows:

rs.Open(CRecordset::forwardOnly, _T(sqlstmt));

 if (! rs.IsEOF())
 {
  // get the field value
  nrs = rs.GetODBCFieldCount();
  for (short index = 0; index < nrs; index++)
  {
   rs.GetFieldValue( index, varVal);

   switch(varVal.m_dwType)
   {
   case DBVT_LONG:
    lVal = varVal.m_iVal;
    break;
   case DBVT_STRING:
    szVal = varVal.m_pstring;
    break;
   default:
    // do nothing
    break;

   }
}
}

In debugging mode, I found it always failed at the line
"rs.GetFieldValue(index, varVal)" when the database table field type is
"nvarchar". It seems that the "DBVT_STRING" is not the correct type for
"nvarchar". How should I fix the problem?

By the way, change the field type "nvarchar" to the type "varchar" is not a
solution for me because I can not change my customer's data structure.

Thanks.

Yan



Relevant Pages

  • query to list field data types
    ... field names, field data types, field lengths, index names, ... if we queried the Customers table in the MS ... ContactName, nvarchar, 30, nulls=yes ...
    (microsoft.public.sqlserver.mseq)
  • retrieve table properties through query?
    ... field names, field data types, field lengths, index names, ... if we queried the Customers table in the MS ... ContactName, nvarchar, 30, nulls=yes ...
    (microsoft.public.sqlserver.setup)
  • Re: query to list field data types
    ... >field names, field data types, field lengths, index names, ... if we queried the Customers table in the MS ... >ContactName, nvarchar, 30, nulls=yes ...
    (microsoft.public.sqlserver.mseq)
  • Re: retrieve table properties through query?
    ... Look within Books Online (within your SQL Server program group) for more information. ... if we queried the Customers table in the MS ... > Northwind SQL DB: ... > ContactName, nvarchar, 30, nulls=yes ...
    (microsoft.public.sqlserver.setup)