CDaoDatabase db;
db.Open(_T("d:\\scores.mdb")); CDaoRecordset rs(&db);
rs.Open(dbOpenDynaset,
_T("SELECT [Student Name], AVG([Test Score]) AS AvgScore "
"FROM Scores GROUP BY [Student Name]")); while (!rs.IsEOF())
{
COleVariant varName;
COleVariant varAvg;
varName = rs.GetFieldValue(_T("student name"));
varAvg = rs.GetFieldValue(_T("AvgScore")); // You know that the return values are BSTR and VT_R8 types.
// if you didn't know, you would have to do some checking
// here. Look at the vt member of the COleVariant to see what
// type the data is. // Do something with the data. This sample prints the
// information to the output window of the debugger.
TRACE(_T("%s\n%f\n"), V_BSTRT(&varName), V_R8(&varAvg));
rs.MoveNext();
}
rs.Close();
db.Close();
db.Open(_T("d:\\scores.mdb")); CDaoRecordset rs(&db);
rs.Open(dbOpenDynaset,
_T("SELECT [Student Name], AVG([Test Score]) AS AvgScore "
"FROM Scores GROUP BY [Student Name]")); while (!rs.IsEOF())
{
COleVariant varName;
COleVariant varAvg;
varName = rs.GetFieldValue(_T("student name"));
varAvg = rs.GetFieldValue(_T("AvgScore")); // You know that the return values are BSTR and VT_R8 types.
// if you didn't know, you would have to do some checking
// here. Look at the vt member of the COleVariant to see what
// type the data is. // Do something with the data. This sample prints the
// information to the output window of the debugger.
TRACE(_T("%s\n%f\n"), V_BSTRT(&varName), V_R8(&varAvg));
rs.MoveNext();
}
rs.Close();
db.Close();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货