Two Methods for replacing database content in batch in Access

Source: Internet
Author: User
In fact, you can use SQL statements in the Access database to replace the content in batches. You only need one sentence to solve the problem. The following two methods are used to solve the problem.

In fact, you can use SQL statements in the Access database to replace the content in batches. You only need one sentence to solve the problem. The following two methods are used to solve the problem.

Today, I encountered a problem where an Access database stores N article records. Now I want to replace some of the content in these articles. The first thing we think of is to go to the website background to modify an article, if there are 1000 articles, you can change the number of times in the background of the website. It is hard to imagine the workload. In fact, you can use SQL statements in the Access database to replace the content in batches. You only need one sentence to solve the problem. The following two methods are used to solve the problem.

Method 1: Modify it by using the query analyzer in the Access Database (Access 2003 is used here)

1. Open the Access database to be modified

2. Click "query" in "object" of the database"

3. Click "create query in design view"

4. Close the "display table" window on the displayed page.

5. Click "View" and select "SQL View". The query window is displayed. You can enter the SQL statement here.

6. Enter the following SQL statement:

Update table SET field = replace (field, "original character", "replacement character ")

You can replace the red text above according to the actual situation. For example, assume that the table is biao, the field is content, the original character is xiazai.jb51.net, And the replacement character is down1.jb51.net, the corresponding SQL statement is as follows:
The Code is as follows:
Update biao SET content = replace (content, "xiazai.jb51.net", "down1.jb51.net ")

7. Click the exclamation point in the toolbar to run it.

Method 2: Use an ASP program to replace characters in batches. The above Code has the character length limit. There is no limit on this.

The ASP program code is provided below. You can see it at first glance:
The Code is as follows:
'The database connection code is omitted here
Dim rs, SQL, text
Set rs = Server. CreateObject ("ADODB. Recordset ")
SQL = "Select content From biao"
Rs. Open SQL, conn, 1, 3
Do While Not rs. Eof
Text = Replace (rs ("content"), "xiazai.jb51.net", "down1.jb51.net ")
Rs ("content") = text
Rs. Update
Rs. MoveNext
Loop
Rs. Close
Set rs = Nothing
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.