Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C, ODBC, and MSAccess

Posted on 1997-04-07
4
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

670 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