ADO umlaute
-
Hallo Leute
habe mir eine ADO Klasse geschrieben. Dieser Verbindet auf einen MS SQL 2005. Leider bekomme ich bei Spalten mit Text keine Umlaute zurück. Lediglich Fragezeichen.
Ein Auszug aus der Executefunktion.
Dies wird in einer DLL ausgeführt.
Ersuche bitte um hilfe.
DankeAFX_MANAGE_STATE(AfxGetStaticModuleState()); m_ulAffectedRows = 0; try { // Prepare the recordset object if ( result == NULL ) { result.CreateInstance( __uuidof( ADODB::Recordset ) ); } else { result->Close(); } // Prepare the query ADODB::_CommandPtr pCommand; pCommand.CreateInstance( __uuidof(ADODB::Command) ); pCommand->PutCommandType( ADODB::adCmdText ); pCommand->PutCommandText( _bstr_t( sqlcommando ) ); pCommand->PutActiveConnection( LPDISPATCH( conn ) ); pCommand->PutPrepared( true ); // Execute the query _variant_t varRowsAffected; ADODB::_RecordsetPtr resulttemp = pCommand->Execute( &varRowsAffected, NULL, 0 ); m_ulAffectedRows = int( varRowsAffected ) >= 0 ? ( unsigned long( varRowsAffected ) ) : 0; ADODB::FieldsPtr theFields = resulttemp->GetFields(); if ( !theFields || theFields->GetCount() <= 0 ) { /* Statement executed */ // sqlexecute( "SELECT @@IDENTITY"); m_lastinsertid = field[1]; return DB_COMMAND_OK; } m_fields.RemoveAll(); result = resulttemp; if ( result->Get_EOF() ) { /* Keine Daten vorhanden */ return DB_EMPTY_QUERY; } for ( long colNum = 1; colNum <= theFields->GetCount(); colNum++ ) { ADODB::FieldPtr theField; theFields->get_Item( _variant_t( colNum - 1 ), &theField ); _variant_t theValue; if ( theField ) { theField->get_Value( &theValue ); } if( theValue.vt != VT_EMPTY && theValue.vt != VT_NULL ) theValue.ChangeType( VT_BSTR ); if( theValue.vt == VT_EMPTY || theValue.vt == VT_NULL ) { m_fields.Add( NULL ); } else { m_fields.Add( (LPCTSTR)theValue.bstrVal ); } } } catch( _com_error& e ) { m_errorMessage = errorMessage( e ); if ( result ) { result.Release(); } return DB_COMMAND_ERROR; } return DB_SELECT_OK;
-
Ich vermute mal, Dein Programm ist nicht mit Unicoder erzeugt!
Also kannst Du doch einen BSTR nicht einfach zu einem LPCTSTR casten!m_fields.Add( (LPCTSTR)theValue.bstrVal );Korrekt ist:
m_fields.Add(CW2T(theValue.bstrVal));Oder USES_CONVERSION, W2T...
-
Hallo
Der Fehler ist schon bei
theField->get_Value( &theValue );
im Variant sind die Umlaute und Sonderzeichen schon nicht vorhanden.
Es liegt übrigens nicht an der Tatsache das die Klasse in einer LIB/DLL ist. Habe es auch ohne versucht.
Habe es auch mit UNICODE versucht.
-
Habs gelöst.
Problem war das MSSQL mit einer anderen Sortiersprache gearbeitet hat.
In ADO sind die Umlaute zwar noch immer weg (VARIANT) aber beim kopieren der Daten in den CString sind sie dann da.