Click to See Complete Forum and Search --> : reading a record
July 19th, 1999, 05:12 AM
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
Paley
July 19th, 1999, 05:17 AM
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?
Burlacu Ovidiu
July 19th, 1999, 05:31 AM
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();
July 19th, 1999, 05:45 AM
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
Paley
July 19th, 1999, 05:54 AM
Use a parameter in your SQL string, you can then just requery to get the new result set
July 19th, 1999, 06:20 AM
Could you give me a snipet of code as an example (for the requery)
Thanx
July 19th, 1999, 07:10 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.