Home Database Mysql Tutorial VB操作access数据库

VB操作access数据库

Jun 07, 2016 pm 03:43 PM
access operate data database connect

第一次用VB来连接Access数据库,由于不了解VB语法,老是出现bug。现在看来,其实很简单,有好几种方法来连接,包括ADO控件、利用ADO对象等方法。由于ADO控件操作局限性太大,本文采用ADO对象来操作。过程如下: 准备工作: 建立数据库 E:\operation.accdb;

第一次用VB来连接Access数据库,由于不了解VB语法,老是出现bug。现在看来,其实很简单,有好几种方法来连接,包括ADO控件、利用ADO对象等方法。由于ADO控件操作局限性太大,本文采用ADO对象来操作。过程如下:


准备工作: 建立数据库 E:\operation.accdb; 建数据表:selection;数据表中,建字段:User,Password,并添加一条记录

点工程->引用 选中Microsoft Activex Data Objects 6.1 Library(注:选择最高版本就行)



1、数据库查询

首先添加控件:添加一个文本框,一个命令按钮

Private Sub Command1_Click()
Dim Conn As New ADODB.Connection '创建ADODB对象,用于连接数据库操作
Dim Rs As New ADODB.Recordset  '创建ADODB对象,用于返回取得的数据库内容
Conn.Open "Provider=microsoft.ace.oledb.12.0;Data Source=E:\operation.accdb"  '连接数据库函数,第一个参数为数据库驱动,第二个参数为数据库路径

sql = "Select Password From select where User='a'" 
'selection请换成你的实际数据表名
Rs.Open sql, Conn, 1, 3 '查询数据库,第一个参数为数据库查询语句,第二个参数为数据库连接,第三个和第四个分别为对数据库的操作权限;
If Rs.EOF Then
MsgBox "没有找到此用户"
Else
Text1.Text = Rs("Password")
End If
Conn.close
Rs.close
End Sub
Copy after login

2、数据插入

首先添加控件:添加两个文本框,一个命令按钮

Private Sub Command1_Click()
Dim s1 As String
Dim s2 As String
Dim Conn As New ADODB.Connection
Conn.Open "Provider=microsoft.ace.oledb.12.0;Data Source=E:\operation.accdb"

s1 = Text1.Text
s2 = Text2.Text
sql = "Insert Into selection Values('" & s1 & "','" & s2 & "')"
Conn.Execute sql
Conn.close
End Sub
Copy after login

3、删除数据库中的某个记录

首先添加控件:添加一个文本框,一个命令按钮

Private Sub Command1_Click()
Dim s As String
Dim Conn As New ADODB.Connection
Conn.Open "Provider=microsoft.ace.oledb.12.0;Data Source=E:\operation.accdb"

s = Text1.Text
sql = "Delete From selection Where User = '" & s & "'"
Conn.Execute sql
Conn.close
End Sub
Copy after login



4、更新数据库某个记录

首先添加控件:添加一个文本框,一个命令按钮


Private Sub Command1_Click()
Dim s As String
Dim Conn As New ADODB.Connection
Conn.Open "Provider=microsoft.ace.oledb.12.0;Data Source=E:\operation.accdb"
s = Text1.Text
sql = "Update selection Set [Password] = '" & s & "' Where [User] = 'a'"

Conn.Execute sql
Conn.Close
End Sub
Copy after login


总结

首先是建立数据库连接:

Private Sub Command1_Click()
Dim Conn As New ADODB.Connection '创建ADODB对象,用于连接数据库操作
Dim Rs As New ADODB.Recordset  '创建ADODB对象,用于返回取得的数据库内容
Conn.Open "Provider=microsoft.ace.oledb.12.0;Data Source=E:\operation.accdb"  '连接数据库函数,第一个参数为数据库驱动,第二个参数为数据库路径
Copy after login
然后,是对数据库各种操作语句




Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert deepseek pdf How to convert deepseek pdf Feb 19, 2025 pm 05:24 PM

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

How to read dbf file in oracle How to read dbf file in oracle May 10, 2024 am 01:27 AM

Oracle can read dbf files through the following steps: create an external table and reference the dbf file; query the external table to retrieve data; import the data into the Oracle table.

AI startups collectively switched jobs to OpenAI, and the security team regrouped after Ilya left! AI startups collectively switched jobs to OpenAI, and the security team regrouped after Ilya left! Jun 08, 2024 pm 01:00 PM

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI 70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI Jun 13, 2024 pm 03:47 PM

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Jun 25, 2024 pm 07:09 PM

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

See all articles