Results 1 to 3 of 3

Thread: CDBVariant

  1. #1
    Join Date
    Sep 2003
    Posts
    30

    Unanswered: CDBVariant

    Hi

    got small problem. I got three rows in a table

    Index (int)
    Product (varchar)
    Price (float)

    I could successfully connect to the database. I also get the values and store them in a CDBVariant type. I can't put the values into List Control Box.... insertItem always return -1. It ask for LPCTSTR type.


    Anyone can help me please, hanging around here know for hours?

    Please
    Thx


    CODE

    {
    CDBVariant value;
    char sql_statement [2048] = "";

    //CDatabase object "db" created to connect database
    CDatabase db;
    db.OpenEx(_T("DSN=Beauty"),CDatabase::noOdbcDialog );

    //CRecordset object "rs" created to access and manipulate database records.
    CRecordset rs(&db);
    strcpy(sql_statement,_T("SELECT * FROM TestTabelle"));
    rs.Open(CRecordset::forwardOnly,sql_statement);

    //Get quantity from Database
    int n = rs.GetODBCFieldCount( );

    while(!rs.IsEOF())
    {
    for( int i = 0; i < n; i++ )

    {

    rs.GetFieldValue("index",value);
    m_Buy_List.InsertItem(i,LPCTSTR(value.m_lVal)); Won't work at all


    rs.GetFieldValue("product",value.m_pstring);
    m_Buy_List.SetItemText(i,2,LPCTSTR(value));Getting weird String for example "Soap" and ListBox shows "Aq3"


    rs.GetFieldValue("price",value);
    m_Buy_List.SetItemText(i,3,LPCTSTR(value.m_fltVal) ); Won't accept float

    rs.MoveNext( );
    }
    }
    Last edited by Indian; 09-30-03 at 10:23.

  2. #2
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    Perhaps you would get better results on a C++ forum...

    If you know that the values must be strings, and you are retrieving each one explicitly, why not just create three variables (strings), and use those. Seems like it would be a lot easier and less trouble prone.

    If you are concerned about NULLs (which you should be), change your SQL statement to use the ISNULL function on each of the fields you are dealing with:

    SELECT ISNULL(index,0) AS INDEX, ISNULL(product,'') AS PRODUCT, ISNULL(price,0) AS PRICE FROM TestTabelle
    -bpd

  3. #3
    Join Date
    Sep 2003
    Posts
    30
    thx

    i figured another way out.... getFieldValue isn't accepting strings so i converted them in char

    weird.... someday i will find the official way... i will change it then

    iam new into c++ and ms sql... learning by doing

Posting Permissions

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