mfc无法将数据写入access数据库
要执行的操作是将编辑框内的数据写入access数据库,代码如下:voidCOrderlist::OnBnClickedOk(){UpdateData();CStringS...
要执行的操作是将编辑框内的数据写入access数据库,代码如下:
void COrderlist::OnBnClickedOk()
{
UpdateData();
CString S1, S2, S3;
GetDlgItemText(IDC_EDIT1, S1);
GetDlgItemText(IDC_EDIT4, S2);
GetDlgItemText(IDC_EDIT6, S3);
if (S1 == "" || S2 == "" || S3 == "")
{
AfxMessageBox(_T("信息不完整!!!"));
return;
}
myAccess.OnInitADOConn();
try
{
_variant_t vRecordsAffected;
_ParameterPtr pParam1 = myAccess.m_pCommand->CreateParameter(_bstr_t("mName"), adBSTR,
adParamInput, S1.GetLength(), _variant_t(S1));
_ParameterPtr pParam2 = myAccess.m_pCommand->CreateParameter(_bstr_t("mCode"), adBSTR,
adParamInput, S2.GetLength(), _variant_t(S2));
myAccess.m_pCommand->Parameters->Append(pParam1);
myAccess.m_pCommand->Parameters->Append(pParam2);
try
{
myAccess.m_pCommand->Execute(&vRecordsAffected, NULL, adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->Description());
}
if (vRecordsAffected.intVal == 1)
{
AfxMessageBox(_T("添加成功!"));
}
}
catch (_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
while (!myAccess.m_pRecordset->adoEOF)
{
_variant_t var;
CString strValue;
var = myAccess.m_pRecordset->GetCollect("Type");
if (var.vt != VT_NULL)
strValue = (LPCSTR)_bstr_t(var);
AfxMessageBox(strValue);
myAccess.m_pRecordset->MoveNext();
}
CDialogEx::OnOK();
} 展开
void COrderlist::OnBnClickedOk()
{
UpdateData();
CString S1, S2, S3;
GetDlgItemText(IDC_EDIT1, S1);
GetDlgItemText(IDC_EDIT4, S2);
GetDlgItemText(IDC_EDIT6, S3);
if (S1 == "" || S2 == "" || S3 == "")
{
AfxMessageBox(_T("信息不完整!!!"));
return;
}
myAccess.OnInitADOConn();
try
{
_variant_t vRecordsAffected;
_ParameterPtr pParam1 = myAccess.m_pCommand->CreateParameter(_bstr_t("mName"), adBSTR,
adParamInput, S1.GetLength(), _variant_t(S1));
_ParameterPtr pParam2 = myAccess.m_pCommand->CreateParameter(_bstr_t("mCode"), adBSTR,
adParamInput, S2.GetLength(), _variant_t(S2));
myAccess.m_pCommand->Parameters->Append(pParam1);
myAccess.m_pCommand->Parameters->Append(pParam2);
try
{
myAccess.m_pCommand->Execute(&vRecordsAffected, NULL, adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->Description());
}
if (vRecordsAffected.intVal == 1)
{
AfxMessageBox(_T("添加成功!"));
}
}
catch (_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
while (!myAccess.m_pRecordset->adoEOF)
{
_variant_t var;
CString strValue;
var = myAccess.m_pRecordset->GetCollect("Type");
if (var.vt != VT_NULL)
strValue = (LPCSTR)_bstr_t(var);
AfxMessageBox(strValue);
myAccess.m_pRecordset->MoveNext();
}
CDialogEx::OnOK();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |