| 发表于:2007-12-27 17:24:595楼 得分:0 |
bool csdi_adodbdoc::onnewdocument() { if (!cdocument::onnewdocument()) return false; // todo: 在此添加重新初始化代码 // (sdi 文档将重用该文档) //设置数据库连接和sql命令字符串 //m_strconnection = _t("provider=msdasql.1;data source = testdb"); m_strconnection = _t("provider=msdasql.1;data source=testdb"); m_strcmdtext = _t("select * from form_a"); //初始化recordset和绑定指针 m_ptrrs = null; m_piadorecordbinding = null; //初始化com环境 ::coinitialize(null); try { //创建recordset对象 m_ptrrs.createinstance( __uuidof(recordset));//__uuidof关键字。通过它可以进一步简化你在c++语言 中实现com组件的代价。 //打开recordset对象 m_ptrrs-> open((lpctstr)m_strcmdtext,(lpctstr)m_strconnection,adopendynamic, adlockbatchoptimistic, // fix #5: must use adlockbatchoptimistic adcmdtext); //获得指向记录绑定接口的指针 if(failed(m_ptrrs-> queryinterface(__uuidof(iadorecordbinding),(lpvoid*)&m_piadorecordbinding))) _com_issue_error(e_nointerface); //将记录类绑定到recordset m_piadorecordbinding-> bindtorecordset(&m_rsrecset); //获得视图指针 position pos = getfirstviewposition(); csdi_adodbview* pview=(csdi_adodbview*)getnextview(pos); if(pview) pview-> refreshbounddata(); } catch(_com_error &e) { generateerror(e.error(),e.description()); } return true; } | | |
|