Solved

C, ODBC, and MSAccess

Posted on 1997-04-07
4
416 Views
Last Modified: 2012-05-04
I'm writing a program in C using VisulC vers. 1.5 (16 bit), an ODBC driver and a database mdb (MSAccess vers. 2.0).
I have troubles writing a query with a date in the WHERE condition. This code doesn't work:
DATE_STRUCT my date;
SQLPrepare(hstm,"SELECT * FROM TAB WHERE DATE=(?),SQL_NTS);
SQLSetParam(hstm,1,SQL_C_DATE,SQL_DATE,0,0,&mydate,NULL);
mydate.year=1997;
mydate.month=2;
mydate.day=1;
SQLExecute(hstm);
The same code with a string variable in the WHERE condition works perfectly.
Thank you.
Valerio.
0
Comment
Question by:valerio
4 Comments
 
LVL 4

Expert Comment

by:emmons
ID: 1249835
Get rid of the parens around the question mark (in the line
beginning with DATE) and see if that helps.
0
 

Author Comment

by:valerio
ID: 1249836
May be this can help you:
the following code works without problems:

char mystr[5];
strcpy(mystr,"XXXX");
SQLPrepare(hstm,"SELECT * FROM TAB WHERE STR=(?),SQL_NTS);
SQLSetParam(hstm,1,SQL_C_CHAR,SQL_CHAR,4,0,&mystr,NULL);
SQLExecute(hstm);

I have problems only with a date variable.
Thank you
Valerio
0
 

Expert Comment

by:rhg
ID: 1249837
First, you have to locate the cause of the problem (Driver
Manager, Jet Engine etc.). In order to do this, you should
obtain the return code of SQLSetParam() and SQLExecute().
If one of them is SQL_ERROR or SQL_SUCCESS_WITH_INFO, you should
call SQLError() in order to obtain the SQLSTATE and the error
description. Anything else is just guessing.

0
 

Accepted Solution

by:
prade earned 100 total points
ID: 1249838
try to initialize "mydate" BEFORE calling the SQLSetParam()
i think SQLSetParam() will make a copy and won't notice later
changes on "mydate"...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
posix semaphore deadlock 13 114
Test against App 49 133
Need example 5 107
C++ :Change value from  DisableCMD registry 4 51
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now