数据库的读写有关问题
数据库的读写问题
m_pConnection.CreateInstance(_uuidof(Connection));
HRESULT hr;
_bstr_t user("");
_bstr_t pwd("");
source="Driver={SQL Server};Server=(localhost);Uid=sa;Pwd=123456;Database=Info";
hr=m_pConnection->Open(source,user,pwd,16);
if(SUCCEEDED(hr))
{AfxMessageBox("Sucess!");}
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败!");
return FALSE;
}
测试这部分时候,跳出对话框,提示成功。
在OnInitDialog()函数中,
测试这部分
CString strQuery;
strQuery.Format("SELECT * FROM user");
_bstr_t query = strQuery;
_bstr_t source("Driver={SQL Server};Server=(localhost);Uid=sa;Pwd=364691zz;Database=Info");
m_pRecordset->Open(query,source,adOpenDynamic,adLockOptimistic, adCmdText);
出现错误,提示:
abnormal program termination
------解决方案--------------------
再好好看看连接字符串
------解决方案--------------------
试试用ADO助手测试下连接字符串和SQL。
m_pConnection.CreateInstance(_uuidof(Connection));
HRESULT hr;
_bstr_t user("");
_bstr_t pwd("");
source="Driver={SQL Server};Server=(localhost);Uid=sa;Pwd=123456;Database=Info";
hr=m_pConnection->Open(source,user,pwd,16);
if(SUCCEEDED(hr))
{AfxMessageBox("Sucess!");}
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败!");
return FALSE;
}
测试这部分时候,跳出对话框,提示成功。
在OnInitDialog()函数中,
测试这部分
CString strQuery;
strQuery.Format("SELECT * FROM user");
_bstr_t query = strQuery;
_bstr_t source("Driver={SQL Server};Server=(localhost);Uid=sa;Pwd=364691zz;Database=Info");
m_pRecordset->Open(query,source,adOpenDynamic,adLockOptimistic, adCmdText);
出现错误,提示:
abnormal program termination
mfc
数据库
读写
------解决方案--------------------
再好好看看连接字符串
------解决方案--------------------
试试用ADO助手测试下连接字符串和SQL。