Click to See Complete Forum and Search --> : A date-typed parameter in SQLBindParameter makes me crazy,help!


smn
July 22nd, 1999, 02:58 AM
In my program,a date input by user is stored in a variable named "d",
and I must pass it to SQLBindParameter to get records,these
records's data of "abc" field must be greater than d.

SQLDATE d[]="1996-12-30";//a variable stored with user's input
sr=SQLPrepare(stmt,(SQLCHAR*)"select * from stock where abc>{d ?}",SQL_NTS);
sr=SQLBindParameter(stmt,1,SQL_PARAM_INPUT, SQL_C_DATE,SQL_DATE,10,0,d,0,&length);
sr=SQLExecute(stmt);

sr returns SQL_ERROR,I don't know why.
I try to define d as CTime class,error;
Change {d ?} to {?} or ?,error;
Change 10,0 to SQL_TYPE_DATE,SQL_TYPE_DATE,error;
Change the last 0 to sizeof(d),error.
I can't find any example of this in books,it really stops my work.
Thank you all for reply or giving me suggestion.

I know that if I type this,sr returns success:
SQLExecDirect(stmt,(SQLCHAR*)"select * from stock where abc>{d '1996-12-30'}" (or abc>#1996/12/30#)
,SQL_NTS);
Best Regards
simon
smn@21cn.com

bimmer boy
July 22nd, 1999, 07:34 AM
i have found it alot easier to bind dates to strings and parse them out myself. it works alot better for me. you may want to give that a try.

miked

hvisitor
July 22nd, 1999, 08:47 AM
Try these fllowing codes
char stmt[MAX_LENGTH];
char *DateStr= "1999-07-22";
sprintf(stmt,"select * from stock where d>'%s'\0 ",DateStr);
sr=SQLExecute(stmt);

July 27th, 1999, 03:42 AM
Dear friend,

Try to do the following :

sr=SQLPrepare(stmt,(SQLCHAR*)"select * from stock where abc > ?",SQL_NTS);

sr=SQLBindParameter(stmt,1,SQL_PARAM_INPUT, SQL_C_DATE,SQL_DATE,0,0,&d,0,&length);

Now before calling SQLExecute(...), fill members of "d" and execute it...

Bye...

Buddie
March 21st, 2002, 08:29 PM
Hi ,

I am following your thread in Codeguru
Iam also doing some ODBC/C++ related work .

From SQL server i wanna retrive a coloumn of datatype
"smalldatetime"

The code looks like
SQL_TIMESTAMP_STRUCT dateTime;
dateTime.year =2002;
dateTime.month =3;
dateTime.day =30;
dateTime.hour =8;
dateTime.minute =30;
dateTime.second =45;
dateTime.fraction =0;
cbPartID5=0;
if ( (nSqlCode =SQLBindParameter(hStmtPrim, 5,SQL_PARAM_INPUT, SQL_C_TIMESTAMP ,SQL_TIMESTAMP , SQL_TIMESTAMP_LEN, 0, &dateTime, 0, &cbPartID5)) != SQL_SUCCESS &&nSqlCode != SQL_SUCCESS_WITH_INFO )
{
AfxMessageBox("error");
// cdb.Close ();
return false;

}
this function working fine but
if ( ( nSqlCode = SQLExecute( hStmtPrim ) ) != SQL_SUCCESS && nSqlCode != SQL_SUCCESS_WITH_INFO &&nSqlCode != SQL_NO_DATA )
{

return false;
}

This function is not working properly and giving" -1" as return value.

i changed the sixt parameter (ColumnSize) to 50
and i tried with SQL_C_TIMESTAMP and SQL_TIMESTAMP and result was same ...


can u pls give some suggestions for the same
thanx in advance
sagar


Software Engineer