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