|
-
July 19th, 1999, 05:12 AM
#1
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
-
July 19th, 1999, 05:17 AM
#2
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?
-
July 19th, 1999, 05:31 AM
#3
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();
-
July 19th, 1999, 05:45 AM
#4
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
-
July 19th, 1999, 05:54 AM
#5
Re: reading a record
Use a parameter in your SQL string, you can then just requery to get the new result set
-
July 19th, 1999, 06:20 AM
#6
Re: reading a record
Could you give me a snipet of code as an example (for the requery)
Thanx
-
July 19th, 1999, 07:10 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|