Hello.
I'm using Visual C++6.0, and Windows XP. I am trying to connect to a database. I want to add some records to it, reading the values out of edit boxes.
Here is my Code:
CDialog::EnableConnections();
::CoInitialize(NULL);
_ConnectionPtr con;
con.CreateInstance(__uuidof(Connection));
con->Open(L"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\\Documents and Settings\\204504519\\Desktop\\webcam.mdb",_bstr_t (""),_bstr_t(""),adOpenUnspecified);
_CommandPtr cmd;
cmd.CreateInstance(__uuidof(Command));
cmd->ActiveConnection = con;
cmd->CommandText = "Select * from Main";
_RecordsetPtr pRs;
pRs.CreateInstance(__uuidof(Recordset));
pRs ->putref_Source(cmd);
_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;
pRs->Open(vNull,vNull,adOpenDynamic,adLockOptimistic,adCmdUnknown);
COleSafeArray vaFieldlist;
vaFieldlist.CreateOneDim(VT_VARIANT,6);
long lArrayIndex[1];
lArrayIndex[0] = 0;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("UserName")));
lArrayIndex[0] = 1;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("Name")));
lArrayIndex[0] = 2;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("Surname")));
lArrayIndex[0] = 3;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("IDNum")));
lArrayIndex[0] = 4;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("Password")));
lArrayIndex[0] = 5;
vaFieldlist.PutElement(lArrayIndex,&(_variant_t("UserType")));
COleSafeArray vaValuelist;
vaValuelist.CreateOneDim(VT_VARIANT,6);
lArrayIndex[0] = 0;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("")));
lArrayIndex[0] = 1;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("")));
lArrayIndex[0] = 2;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("")));
lArrayIndex[0] = 3;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("")));
lArrayIndex[0] = 4;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("")));
lArrayIndex[0] = 5;
vaValuelist.PutElement(lArrayIndex,&(_variant_t("Client")));
pRs->AddNew(vaFieldlist,vaValuelist);
UpdateData(TRUE);
_variant_t vName,vVal;
vName.SetString("UserName");
vVal.SetString(m_UName);
pRs->Update(vName,vVal);
vName.SetString("Name");
vVal.SetString(m_Name);
pRs->Update(vName,vVal);
vName.SetString("Surname");
vVal.SetString(m_Surname);
pRs->Update(vName,vVal);
vName.SetString("IDNum");
vVal.SetString(m_IDNum);
pRs->Update(vName,vVal);
vName.SetString("Password");
vVal.SetString(m_Password);
pRs->Update(vName,vVal);
vName.SetString("UserName");
vVal.SetString(m_UName);
pRs->Update(vName,vVal);
vName.SetString("UserType");
vVal.SetString(m_UType);
pRs->Update(vName,vVal);
pRs->Close();
con->Close();
CoUninitialize();
CDialog::OnOK();
}
void CNew::OnCancel()
{
CDialog::OnOK();
But I get this error:
Microsoft Visual C++ Library
Runtime Error
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
Your help will be greatly appreciated ;)
Thanks,
Emily