Solved

C, ODBC, and MSAccess

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
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…
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 reading files in the C programming language.
Suggested Courses

626 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