468,504 Members | 1,946 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

SQLExecDirect in C++

1
Hi

i am using the following code for my development work
[code=c]
/* Connect to data source */

retcode = SQLConnect(hdbc, (SQLCHAR*) "mvr", SQL_NTS,
(SQLCHAR*) "venk", SQL_NTS,
(SQLCHAR*) "ram", SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
/* Allocate statement handle */
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
/* Process data */
unsigned char query1[256];
sprintf((char*)query1,
"SELECT [col1], [col2], FROM MY_DATA WHERE
Expand|Select|Wrap|Line Numbers
  1.  = \'%s\' ",
  2.                 pszCode );
  3.  
  4.               retcode = SQLExecDirect( hstmt, (SQLCHAR *)query1, SQL_NTS);
  5.  
  6. //////////////////////////////
  7.  
But above code is unable to retrive the data from DB.

Can you please give me any suggestions.

where as same query if i run in sql analyzer the values are coming correctly.

Thanks in advance

Venkat
Mar 18 '08 #1
1 5168
sicarie
4,677 Expert Mod 4TB
Hi

i am using the following code for my development work
[code=c]
/* Connect to data source */

retcode = SQLConnect(hdbc, (SQLCHAR*) "mvr", SQL_NTS,
(SQLCHAR*) "venk", SQL_NTS,
(SQLCHAR*) "ram", SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
/* Allocate statement handle */
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
/* Process data */
unsigned char query1[256];
sprintf((char*)query1,
"SELECT [col1], [col2], FROM MY_DATA WHERE
Expand|Select|Wrap|Line Numbers
  1.  = \'%s\' ",
  2.                 pszCode );
  3.  
  4.               retcode = SQLExecDirect( hstmt, (SQLCHAR *)query1, SQL_NTS);
  5.  
  6. //////////////////////////////
  7.  
But above code is unable to retrive the data from DB.

Can you please give me any suggestions.

where as same query if i run in sql analyzer the values are coming correctly.

Thanks in advance

Venkat
My guess is the SELECT query is being interpreted in the C program. Did you try storing it, and then printing it out - make sure all the proper characters are there?
Mar 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Victorb17 | last post: by
4 posts views Thread by Dave | last post: by
138 posts views Thread by Ian Boyd | last post: by
3 posts views Thread by leejwen | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.