473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 5537
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

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

Similar topics

0
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL...
2
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty...
7
by: Együd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type to another and after this I made all the...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
3
by: Victorb17 | last post by:
I am building a windows app, and need to connect to a Microsoft Access Database. How might I go about doing this? I know sql if that helps any. I am using Dev C++ and writing in C
4
by: Dave | last post by:
Hey guys, I have an ODBC problem that has me stumped. I wrote a VBA script to run in Microsoft Excel that pulls data out of an application using that application's ODBC driver and puts it into...
138
by: Ian Boyd | last post by:
i've been thrown into a pit with DB2 and have to start writing things such as tables, indexes, stored procedures, triggers, etc. The online reference is only so helpful. The two pdf manuals are...
3
by: leejwen | last post by:
I'd like to execute this SQL by SQLExecDirect, select * from abc where A = 'ab%'; Could anybody know how? but attention, below is just not working _stprintf((char *)szSqlCommand, "select *...
2
by: mailravid | last post by:
Hi, When I execute SQLExecDirect() in C++, and if my link between server and client is fluctuating, it returns after a long time and my application hangs. why is this happenning can any give...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.