Home > Software engineering >  Insert data problem VS2008mfc connecting ORACLE database
Insert data problem VS2008mfc connecting ORACLE database

Time:09-16

As title, I turned on the oracle database, and then use the m_pRecordset - & gt; AddNew (); To insert a new record is successful, use (theApp. M_pConnection) - & gt; Execute ((_bstr_t) StrSQL3, NULL, adCmdText); But there has been no success, during which there is no error, the end of the normal procedure, but the database record values did not increase,

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:

reference 1st floor selling fruit net reply:
do you want to give you move to the VC area?

Over your face,,, isn't this oracle insert statements Execute this question?

CodePudding user response:

INSERT INTO your code, in addition to the VISIBILITY (sampling time, VISIBILITY) VALUES (' % s' s # # %,) this sentence, the other is not PL/SQL, can't help it

CodePudding user response:

reference yaiger reply: 3/f
INSERT INTO your code, in addition to the VISIBILITY (sampling time, VISIBILITY) VALUES (' % s' s # # %,) this sentence, the other is not PL/SQL, couldn't help


Ok, thank you for your help, beginner rookie really silly points not clear, my mobile in area, thank you again,

CodePudding user response:

The original poster hello, I recently doing a MFC in VC6 through ado connection Oracle, has been stuck in connecting to the database, code and the connection string tried various formats, now doubt was the cause of the system environment, the original poster can you introduce your project configuration environment?
  • Related