Previous: MFC links Access 2007 database
The next step is to say how to insert data into an Access 2007 database (the web looked under, said a little vague, directly to see the effect )
Main steps:
1 first generate SQL Statement 2 with sprintf and then execute the SQL statement.
The effect is as follows:
Main code:
CString strconn,strdbname;//serv103_serv_link_acces (); if (m_pconnection->state) {m_precordset.createinstance (" ADODB. Recordset ");//m_pconnection->close (); If the connection is already open, close it try{int m_id =1;int m_qh =1;int m_value =1;//char *sql = ""; Char buffer[256];sprintf (buffer, "insert into D Zvalues (Dzid,dzqh,dzvalue) VALUES ('%d ', '%d ', '%d ') ", m_id,m_qh,m_value); M_pconnection->execute (buffer,& Recordsaffected,adcmdtext);//m_pconnection->execute ("CREATE TABLE users (ID integer,username text,old Integer,birthday DATETIME) ", &recordsaffected,adcmdtext);//m_pconnection->execute (" INSERT into users (ID, Username,old,birthday) VALUES (1, ' Washington ', +, ' 1970/1/1 ') ", &recordsaffected,adcmdtext);} catch (_com_error *e) {AfxMessageBox (E->errormessage ());}} M_pconnection->close (); If the connection is already open, close it
VC link Access database insert variable to table