CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Guest

    reading a record

    How can I read a record from an open database by sending a query.

    example:
    I open the database
    I open a recordset with an SQL query
    I read a single column (the only one retrieved)
    I do some non database stuff
    I make a new query and execute it
    I read another column(the only one retrieved)
    .
    .
    .
    And so on
    I then close the database.

    please help


  2. #2
    Join Date
    Jun 1999
    Posts
    6

    Re: reading a record

    There is no definitive answer to this question, other than 'you can do it in myriad ways'.

    What database are you using?
    How are you connecting to the database?


  3. #3
    Join Date
    Jul 1999
    Location
    Romania - Iasi
    Posts
    558

    Re: reading a record

    Do this:

    CDatabase db;
    db.Open("your_db");
    CRecordset rs(&db);
    rs.Open(CRecordset::forwardOnly, sqlString );

    CDBVariant value;

    while( !rs.IsEOF() )
    {
    rs.GetFieldValue( (int)0, value, TYPE_OF_VALUE );//for TYPE_OF_VALUE see help
    //do something with the value;
    rs.MoveNext();
    }

    rs.Close();
    db.Close();





  4. #4
    Guest

    Re: reading a record

    here is the code I am using on a MS Access db:

    CDatabase dbm1;
    CRecordset rsm1(&dbm1);
    if (rsm1.IsOpen()) rsm1.Close();
    if (dbm1.IsOpen()) dbm1.Close();
    strConnect = _T("ODBC;DSN=mydb;UID=;PW=;");
    dbm1.Open("",FALSE,FALSE,strConnect,FALSE);

    strSQL = _T("SELECT answer FROM Table WHERE number=10 ");
    rsm1.Open(CRecordset::snapshot, strSQL);
    rsm1.GetFieldValue(0, m_string);



    now, I want to pick another "number" that is not in sequence and get the "answer" without having to close and reopen the database




  5. #5
    Join Date
    Jun 1999
    Posts
    6

    Re: reading a record

    Use a parameter in your SQL string, you can then just requery to get the new result set


  6. #6
    Guest

    Re: reading a record

    Could you give me a snipet of code as an example (for the requery)

    Thanx


  7. #7
    Guest

    Re: reading a record one more thing please

    I know that I must requery, I dont know how.
    I know that I can use:
    rsm1.Requery();
    but how do I set a new SQL string befor I do this


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