小弟遇到一个问题,vc++6.0连接access数据库的,这个数据库由于设制了工作组(*.mdw)且设定了用户名和密码,数据库(*.mdb)本身也有一个密码,请各位高手指点一下如何连接此类数据库,举个例子什么的。有demo更完美(可发到[email protected])。本人实在愚钝,在此先谢谢各位了。
解决方案 »
- 求救:在VC2008下,自己生成了一个静态库文件DataOperator.lib,在另外的工程只使用时,编译时出现错误:LNK1104: 无法打开文件“DataOperator.lib”,
- vc生成的exe可执行文件怎么样可以做成一个可安装程序?
- 关于对话框字体的问题
- 扁平滚动条的问题
- 我想在SDK程序中实现Activex控件的调用,控件事件的绑定,请问怎么实现
- 控件完全盖住对话框的下边?
- 简单的小问题,在线等待
- 帮忙up也送分,关于聚合:exe式的组件不能聚合别的组件吗?
- 重载操作符()是啥意思?能举一个重载并应用的例子吗?
- 菜问题,对话框的背景图如何添加?
- 用VC怎么得到CPU支持的最大线程数 请高手指教
- CMarkup如何添加到VC6工程中
{
BOOL bSuccess = FALSE; if( lpTable == NULL || lpSqlExecute == NULL )
return E_FAIL; IADORecordBinding *picRs = NULL;
_RecordsetPtr pRs("ADODB.Recordset");//初始化记录查询
_ConnectionPtr pConn("ADODB.Connection" );//初始化记录连接
_CommandPtr pCmdChange = NULL; CString strSql,chSqlSentence; strSql = strSql +
_T("Provider=Microsoft.Jet.OLEDB.4.0;") +
_T("Data Source = ") +
m_szMdbPath +
_T(";Persist Security Info=False;Jet OLEDB:Database Password=") +
m_lpPass; try
{
pConn->Open((_bstr_t)strSql, "", "", adModeUnknown);//打开数据库
pRs->QueryInterface(
__uuidof(IADORecordBinding), (LPVOID*)&picRs); TESTHR(pCmdChange.CreateInstance(__uuidof(Command)));
pCmdChange->ActiveConnection = pConn;
pCmdChange->CommandText = lpSqlExecute; // Open titles table, casting Connection pointer to an
// IDispatch type so converted to correct type of variant.
TESTHR(pRs.CreateInstance(__uuidof(Recordset)));
pRs->Open ((_variant_t)lpTable, _variant_t((IDispatch *) pConn, true), adOpenStatic, adLockOptimistic, adCmdTable);
// Clear extraneous errors from the Errors collection.
pConn->Errors->Clear(); // Use the Connection object's execute method to
// execute SQL statement to restore data.
pConn->Execute(lpSqlExecute, NULL, adExecuteNoRecords); // Retrieve the current data by requerying the recordset.
pRs->Requery(adCmdUnknown); //pRs->Update();
pRs->Close(); bSuccess = TRUE;
}
catch (...)
{
if ( pRs != NULL )
pRs->Close(); if ( pConn != NULL )
pConn->Close(); pRs = NULL;
pConn = NULL;
return E_FAIL;
} pConn->Close();
return S_OK;
}