16,471
社区成员
发帖
与我相关
我的任务
分享
int CDB::AddData(const CString strSQL)
{
cmd->CommandText=_bstr_t(strSQL);
try
{
cmd->Execute(NULL,NULL,adCmdText);
con->CommitTrans();
return 1;
}
catch (_com_error e)
{
//CString err;
//err.Format(_T("%s"));
//AfxMessageBox(err);
con->RollbackTrans();
return -1;
}
}
//在一个窗体里调用却出错
CDB db;
int i;
i=db.AddData(_T("INSERT INTO DevType VALUES (832,'743','44faderfa')"));
if (i==1)
{
AfxMessageBox(_T("success"));
}
else
{
AfxMessageBox(_T("failure"));
}
_CommandPtr cmd;
cmd.CreateInstance("adodb.command");
cmd->ActiveConnection=theApp.con;
cmd->CommandText=_bstr_t("INSERT INTO DevType VALUES (823,'232','232')");
cmd->Execute(NULL,NULL,adCmdText);
try
{
AfxOleInit();
}
catch(_com_error e)
{
CString err;
err.Format(_T("Initialize OLE Fail:%s"),e.ErrorMessage());
AfxMessageBox(err);
}
try
{
con.CreateInstance(_uuidof(Connection));
}
catch (_com_error e)
{
CString err;
err.Format(_T("Create Connection Error:%s"),e.ErrorMessage());
AfxMessageBox(err);
}
try
{
con->Open(_bstr_t("Provider=OraOLEDB.Oracle.1;Password=cvicse2;Persist Security Info=True;User ID=mtws;Data Source=mtws"),"","",-1);
AfxMessageBox(_T("open database success"));
//return 0;
}
catch (_com_error e)
{
CString err;
err.Format(_T("Open Database Error:%s"),e.ErrorMessage());
//return -1;
//AfxMessageBox(err);
}
try
{
cmd.CreateInstance("ADODB.Command");
cmd->ActiveConnection=con;
}
catch (_com_error e)
{
CString err;
err.Format(_T("Create Command Error:%s"),e.ErrorMessage());
AfxMessageBox(err);
}