CDatabase db; CRecordSet rt(&db);db.Open(); CRecordSet.Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );lpszSQL A string pointer containing one of the following: 1A NULL pointer. 2The name of a table. 3An SQL SELECT statement (optionally with an SQL WHERE or ORDER BY clause). 4A CALL statement specifying the name of a predefined query (stored procedure). Be careful that you do not insert whitespace between the curly brace and the CALL keyword. For more information about this string, see the table and the discussion of ClassWizard’s role under Res
OLEDB就是建立在ADO的基础之上的
这篇文章是对CDaoRecordset扩充,你可以参考一下写出基于CRecordset的类
MSDN sample
lSet.Open(CRecordset::snapshot,strsql,CRecordset::readOnly);你可以用short filecount = lSet.GetODBCFieldCount() 获得字段的数目
CODBCFieldInfo& fieldinfo ;for(int i=0;i<fieldcount;i++)
{
lSet.GetODBCFieldInfo(i,fieldinfo); //获得字段的类型和名称,自动绑定用到的信息可以从这里获得
}知道字段的数目,字段的类型,字段的名称,就可按照记录数提取记录的内容了。如果你懒一点,你可以用CDBVariant 类型来代替所有字段的类型。
CDBVariant t
int nId;
lSet.GetFieldValue("id",t);
ASSERT(t.m_dwType==DBVT_LONG);
nId = t.m_lVal;
Item.nForumId = nId; lSet.GetFieldValue("ParentId",t);
ASSERT(t.m_dwType==DBVT_LONG);
nId = t.m_lVal;
Item.nParentId = nId;
数据库中其实各个字段的绑定系可以用代码进行,仲记唔记得记录结果集中的各个对象用法?
其实只要你熟悉结果集的对象,此问题就话甘快搞掂。
编程不要依靠人地的代码,世上最好的代码仲系要靠自己我自己都曾经系呢个问题上搞了几个礼拜,希望你认真的去睇吓个结果集的对象用法。广州的wealth
“胡说”一词不知何解,这儿这么多高手,对“OLEDB就是建立在ADO的基础之上的”应有正确的理解吧!ADO我用了3年了,只是这次想换个方式。谢谢masterz、Tasehouny、wealth等,我将尽快尝试,一有结果,马上给分
CRecordSet rt(&db);db.Open();
CRecordSet.Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );lpszSQL A string pointer containing one of the following: 1A NULL pointer.
2The name of a table.
3An SQL SELECT statement (optionally with an SQL WHERE or ORDER BY clause).
4A CALL statement specifying the name of a predefined query (stored procedure). Be careful that you do not insert whitespace between the curly brace and the CALL keyword.
For more information about this string, see the table and the discussion of ClassWizard’s role under Res