C语言连接数据库

举个例子,连接SQL:
  // 打开数据库
   strDBClass.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s"), m_strUnEntryptMdbFilePath,m_strMDBPassword);
  // 创建连接
  HRESULT hr = m_pConnection.CreateInstance(_uuidof(Connection));
  _ConnectionPtr m_pConnection->Open(m_strDBClass,_T(""),_T(""),adConnectUnspecified);
  // 声明表单指针
  _RecordsetPtr pBandRecordset;
  pBandRecordset.CreateInstance(__uuidof(Recordset));
  // 执行语句
  CString strSQL(L"SELECT * FROM [Band]");
  m_pConnection->Execute((LPCTSTR)strSQL,NULL,0);
  // 提取某一项 例如BandInfo
  int iBandInfo = wcscmp(colum, L"BandInfo");
  while(!recordsetPtr->adoEOF)
  {
  var = recordsetPtr->GetCollect(colum);
  if(var.vt != VT_NULL)
  strName = (LPCSTR)_bstr_t(var);
  recordsetPtr->MoveNext();
  }

posted @ 2015-11-18 14:28  徐一贺  阅读(3139)  评论(0编辑  收藏  举报