VB6.0 SQL server operations (iii) -- data deletion (deletion)

Source: Internet
Author: User

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 ......

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.