Skip to content

Instantly share code, notes, and snippets.

@chenbojian
Last active September 4, 2022 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenbojian/d3cf5c60328049d7054afe1a9404e1ee to your computer and use it in GitHub Desktop.
Save chenbojian/d3cf5c60328049d7054afe1a9404e1ee to your computer and use it in GitHub Desktop.
MFC CRecordset
void func() {
CDatabase db;
CRecordset rs(&db);
db.OpenEx("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\dbo.mdb;");
db.ExecuteSQL("select * from Sporter");
rs.Open(CRecordset::dynaset, "select * from [Sporter]", CRecordset::none);
BOOL a = rs.CanAppend();
CDBVariant varValue;
int count = 0;
int nFields = rs.GetODBCFieldCount();
while (!rs.IsEOF())
{
for (int index = 0; index < nFields; index++)
{
rs.GetFieldValue(index, varValue);
// do something with varValue
}
rs.MoveNext();
count++;
}
rs.Close();
db.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment