Solved

C, ODBC, and MSAccess

Posted on 1997-04-07
4
423 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

856 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