Solved

C, ODBC, and MSAccess

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now