VB6.0 SQL server operations (2) -- data input (ADD)

Source: Internet
Author: User

Use VB to send SQL statements
You can use the data binding control to enter data and use SQL statements to enter data in the server database.


1. Use the data binding control to input data

Using the data binding control to input data can run less code to input data into the database. After data binding, since the data binding control is already connected to the data table, therefore, you only need to add a new blank record through the addnew method of the ADO control, and then save the current record through the update method to complete data input to the database.

Example: Add a record to the database

Private sub into add_click () adodc1.recordset. addnewend subprivate sub cmdsave_click () dim I as long for I = 0 to 6 adodc. recordset. fields (I ). value = text (I + 1 ). text next I adodc1.recoedset. update msgbox "information added! "End sub

2. Use the insert statement to input data

Use SQL statements to input data and execute SQL statements using the execute method of the connection object. The syntax is as follows:

Connection.exe cute string, number of records, string parameter

Example: Add a student information to student database

Dim cnn as ADODB.conectionDim rst as ADODB.recordsetPrivate sub Form_Load()    set cnn=New ADODB.connection    set rst=new ADODB.recordset    cnn.open"provider=SQLOLEDB;Persist security Info=True;User ID=sa;Initial Catalog=student;Data Source=."    rst.open"select * from student_info",cnn    set MSHFlexGrid.DataSource=rstEnd SubPrivate sub cmdAdd_click()   cnn.execute"insert into student_info(txtSID,txtName,txtSex;txtBornData,txtRuDate,txtClassNo)" & _      "value('" & txtSID & "','" & txtName & "','" & txtSex & "','" & txtBornDate & "','" & txtRuDate & "','" & txtClassNo & "')"End Sub

Related Article

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.