Re: Convert Char to LPCOLESTR using OLEDB.H
"Long, Matthew Jr. (Inland)" <[email protected]> Thu, 18 Apr 2002 00:01:55 -0500
| Newsgroups | gmane.comp.windows.devel.oledb.devel |
|---|---|
| Message-ID | <[email protected]> |
Well I'm not using MFC so A2COLE is out. This is just a small WIN32 app that get messages from IBM Mqseries and Inserts them into a Oracle database. When I look at the value of the variable in the debug window I noticed it has the address, and to the right of the address it says `string' when I do the following..... lpOleDb.m_szSQLCommand = OLESTR( "SELECT COUNT(*) FROM DEVDTA.F5549018 "); But when I convert it using WCHAR it doesn't display string in the debug window on the variable, therefore the SetCommandText function fails. Any ideas how to append to a string using OLESTR? I've tried passing it a variable and that doesn't work. Thanks! Matt -----Original Message----- From: Long, Matthew Jr. (Inland) Sent: Wednesday, April 17, 2002 8:39 PM To: [email protected] Subject: FW: [OLEDB_DEV] Convert Char to LPCOLESTR using OLEDB.H -----Original Message----- From: Duncan Smith [mailto:[email protected]] Sent: Wednesday, April 17, 2002 6:19 PM To: [email protected] Subject: Re: [OLEDB_DEV] Convert Char to LPCOLESTR using OLEDB.H Matt, There are some useful string conversion macros defined in an ATL include file, atlconv.h. If you are not already using ATL in your project, I think you just need to #include <atlconv.h> to use the macros. Here is your sample modified to use the A2COLE macro, which converts an LPCSTR to an LPCOLESTR: char m_szSQLCommand[6000]; USES_CONVERSION; strcat(m_szSQLCommand," SELECT COUNT(*) FROM DEVDTA.F5549018 "); m_pCommandText->SetCommandText(DBGUID_DBSQL, A2COLE(m_szSQLCommand) ); Another alternative is to use the Win32 API MultiByteToWideChar. Yet another alternative is to use WCHAR in place of char and wcscat in place of strcat, etc. Then no string conversion is required. Duncan Smith -----Original Message----- From: Long, Matthew Jr. (Inland) [mailto:[email protected]] Sent: Wednesday, April 17, 2002 7:00 PM To: [email protected] Subject: [OLEDB_DEV] Convert Char to LPCOLESTR using OLEDB.H I'm trying to use OLEDB.H for the first time, and I got everything working the way I want except for the T-SQL Command that I build on the fly. I have a char variable that I append to using strcat. I need to convert this char buffer to LPCOLESTR, I just don't know how, at least to where the SetCommandText method will recononize the text in the buffer. // My char buffer looks like this...... char m_cSQLCommand[6000]; strcat(m_cSQLCommand," SELECT COUNT(*) FROM DEVDTA.F5549018 "); // The following is the OleDB Interface I'm using to pass my T-SQL buffer string. // This compiles with no errors but it doesn't work. m_pCommandText->SetCommandText(DBGUID_DBSQL, (LPCOLESTR) m_szSQLCommand ); // Note if I do it this way it works! But this isn't going to work for me, because I have to build this string on the fly, and the statement can be different each time I loop through. m_pCommandText->SetCommandText(DBGUID_DBSQL, OLESTR("SELECT COUNT(*) FROM DEVDTA.F5549018 ")); Any ideas would be appreciated..... VC 6.0 SP5 Win32 Thanks! Matt