VC link Access database insert variable to table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.