CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Posts
    57

    A date-typed parameter in SQLBindParameter makes me crazy,help!

    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
    [email protected]



  2. #2
    Join Date
    Jun 1999
    Posts
    315

    Re: A date-typed parameter in SQLBindParameter makes me crazy,help!

    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

  3. #3
    Join Date
    Jul 1999
    Posts
    6

    Re: A date-typed parameter in SQLBindParameter makes me crazy,help!

    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);


  4. #4
    Guest

    Re: A date-typed parameter in SQLBindParameter makes me crazy,help!

    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...



  5. #5
    Join Date
    Aug 2001
    Location
    Korea
    Posts
    35

    Re: A date-typed parameter in SQLBindParameter makes me crazy,help!

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured