vc数据库知识

在连接SQL数据库时,数据库的链接:

_bstr_t strConn="Provider=SQLOLEDB.1;Data Source=.;Initial Catalog=db_test;Integrated Security=SSPI;Persist Security Info=False";

_ConnectionPtr m_pConnection;

m_pConnection.CreateInstance(__uuidof(connection));

try

{

  m_pConnection->Open(strConn,"sa","123",adModeUnkonwn);

}

catch(_com_error e)

{

  AfxMessageBox(e.Description());

}

获得数据库的数据集:

_RecordsetPtr m_pRecordset;

m_pRecordset.CreateInstance(__uuidof(Recordset));

try

{

  if(m_pConnection==NULL)

  {

    打开数据库;

  }

  m_pRecord->Open(sql,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adcmdText);

}

catch(_com_error e)

{

  AfxMessageBox(e.Description());

}

return m_Recordset;

相关文件下载:

/Files/yangxiaoluck/ADOS.rar

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2010-10-14 11:02  luck_net  阅读(145)  评论(0编辑  收藏  举报