We have already mentioned data entry. Today we will talk about data deletion.
When using VB to delete data, you can not only use the delete statement in the SQL statement, but also use the delete method of the ADO control to delete data.
1. delete data using the ADO control
When you use the delete method of the ADO control to delete data, the deleted data is deleted on the surface. In fact, the data still exists in the memory, in this case, you must use the update method of the ADO control to completely delete the data.
For example, to delete a specified record in a table:
Adodc1.Recordset.DeleteAdodc1.Recordset.Update
For example, you can use the delete method of the ADO control to delete the specified data in the table:
Privatesub form_load () adodc1.connectionstring = "provider = sqloledb; persist securityinfo = true; user id = sa; initail catalog = student; Data Source =. "adodc1.commandtype = ad1_text adodc. recordsource = "select * fromstudent_info" set maid click () adodc1.recordset. delete if msgbox ("are you sure you want to delete the specified data? ", Vbyesno," prompt ") = vbyest1_adodc1.recordset. Refresh end ifend sub
2. Execute the delete statement to delete data.
Using the delete statement to delete data not only deletes one or more specified statements, but also deletes all data in the data table.
For example, execute the delete statement in VB to delete all data in the student table.
Cnn.Execute"deletefrom student"
You can use the WHERE clause to limit the conditions after the delete statement to delete the data that meets the conditions.
For example, delete data older than 25 in student.
CNN. Execute "delete from student where age> '25 '"
3. delete data in the column
Whether using the delete method of the ADO control or the delete statement to delete data, all data in one or more rows is deleted. If the data in some rows in the table needs to retain information in some columns, using the delete method or delete statement of the ADO control is troublesome.
You can delete data from a table by updating the data in the deleted column to null.
For example, you can use the ADO control update method to delete data in columns in a table.
PrivateSub Command1_Click() Adodc1.Recordset.Update 1.NullEnd Sub
Skillfully use data deletion methods to facilitate learning.
We will continue to post "data modification", "Data Query", and so on in subsequent blogs. Please wait ......