Below is the code:
First connect to the oracle server inside the application framework class
Try//connect to the database
{
M_pConnection. CreateInstance (__uuidof (Connection));
_bstr_t strConnect="Provider=OraOLEDB. Oracle. 1; User ID='system'; Password='tiger'; Data Source=wouldn; Persist Security Info=False; ";
M_pConnection - & gt; Open (strConnect, "system", "tiger", adModeUnknown);
}
Catch _com_error (e)
{
AfxMessageBox (TEXT (" the database connection error!" ));
AfxMessageBox (e.D escription ());
The exit (1);
}
Below is inserted into the database code, that is, there is a problem of code
M_pRecordset. CreateInstance (" ADODB. You ");//create instances you
Cstrings strSQL="select * from VISIBILITY";//connect the VISIBILITY list
Try
{
M_pRecordset - & gt; Open ((_variant_t) strSQL, (IDispatch *) theApp. M_pConnection, adOpenDynamic, adLockOptimistic, adCmdText);
}//m_pConnection I on a set of code has been connected to the oracle server
Catch _com_error * (e)
{
AfxMessageBox (e - & gt; ErrorMessage ());
}
Cstrings StrSQL3;
At 19:00 2018/12/20 cstrings Time="";
Cstrings visib="1.3";
StrSQL3. The Format (" INSERT INTO the VISIBILITY (sampling time, VISIBILITY) VALUES (# % s #, '% s') ", "2018/12/20 18:00", "3.0");
//I write my own dead a record to insert
Try {
M_pRecordset - & gt; AddNew ();//a new record
M_pRecordset - & gt; PutCollect (" sampling Time ", _variant_t (Time));//modify each field value
M_pRecordset - & gt; PutCollect (" visibility ", _variant_t (visib));//way, you can achieve with AddNew then add, Update, insert record
//(theApp m_pConnection) - & gt; Execute ((_bstr_t) StrSQL3, NULL, adCmdText);//method 2, use the Execute insert directly, without bugs, but I did not add the data in the database
}
Catch _com_error (e)
{
MessageBox (e.D escription ());
return;
}
M_pRecordset - & gt; The Update (); Update the database//
Below is a method of increasing the effect of the record,
Delete the new record, and then a annotation methods, uncomment the method 2, which is using the Execute insert data, no effect,
I carefully watched me StrSQL3, SQL statements there is no problem, could you tell me what predecessors this problem, compile environment VS2008, MFC framework, x64 platform
CodePudding user response:
Do you want to give you move to the VC area?CodePudding user response: