Home Computer Tutorials Computer Knowledge Using the ADO method in VB to query data tables

Using the ADO method in VB to query data tables

Jan 17, 2024 am 10:15 AM

Using the ADO method in VB to query data tables

How does VB use the ADO method to query a piece of data in a data table

Easy to use controls.

The prerequisite is to connect the adodc control to the database normally

The datagrid control is bound to the adodc control

Private Sub Command1_Click()

'Connect to the database

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database.mdb"

'Inquire

Adodc1.RecordSource = "select * from table where name like '" & Text1.Text & "' and major like '" & Text2.Text & "'"

Adodc1.Refresh

End Sub

How does VB use ADO control to connect to the database and connect with code

First quote ADO: Project--Reference--Select MS ActiveX Data Objects

Code:

Dim Access_Con As Connection

Set Access_Con = New Connection

Access_Con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=" & App_Path & "\FHLdata.mdb;"

Access_Con.Open

Dim rs As Recordset

Set rs = New Recordset

rs.Open "select * from User Management", Access_Con

''''The query results will be in rs. You can bind rs to the datagrid to view the data, etc.

Use ADO control to connect to Access database in VB

When creating a new project, select the data project. At this time, the necessary controls for database programming have been loaded in the toolbox on the left side of the VB6 integrated debugging environment.

Then add the ADODC control and DATAGRID control in the FORM1 form, select ADODC1 for the property DATASOURCE of DATAGRID1, open the ADODC1 control property page to use the connection string, select Generate, select MICROSOFT jet 4.0 OLE DB Provider in the provider option, and then Press to connect to the database, etc. There is a long string in the blank text window using the connection string on the ADODC1 control property page. Note that this string can be copied to the program code for programming. There is a command text (SQL) writing window in the data source of the ADODC1 control property page to write SQL query language. The SQL statements in this window can be copied to the program code for programming.

The main structure of SQL query language is:

Select query field from table name Where query condition statement [sort statement or grouping statement]

The query fields must be separated by (Spanish) commas or replaced by an * sign. It is recommended that the sorting statement in the above query be best used.

SQL query language will tell you if there is an error when the program is running, just make the corresponding changes. I usually press the above connection first, and use "SELECT * FROM TabelName" for SQL debugging. There is no problem. Use a button hole to copy the connection string and SQL query language that need to be copied in the CLICK event of the button control. Save it for later use. Then delete the ADODC1 hole piece, add the ADODC1 control and add other content.

The following are code examples:

Private Sub Form_Load()

Text1 = ""

With Adodc1

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\db1.mdb;Persist Security Info=False"

Adodc1.RecordSource = "select name from b1 order by name"

Adodc1.Refresh

DataGrid1.Refresh

End With

End Sub

Private Sub Text1_Change()

Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\db1.mdb;Persist Security Info=False"

Adodc1.RecordSource = "select name from b1 where name >='" & Text1 & "' order by name"

Adodc1.Refresh'Update query

DataGrid1.Refresh

End Sub

The above is the detailed content of Using the ADO method in VB to query data tables. For more information, please follow other related articles on the PHP Chinese website!

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 Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) Mar 11, 2025 am 11:26 AM

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

How do I edit the Registry? (Warning: Use with caution!) How do I edit the Registry? (Warning: Use with caution!) Mar 21, 2025 pm 07:46 PM

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

How do I manage services in Windows? How do I manage services in Windows? Mar 21, 2025 pm 07:52 PM

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

Discover How to Fix Drive Health Warning in Windows Settings Discover How to Fix Drive Health Warning in Windows Settings Mar 19, 2025 am 11:10 AM

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

which application uses ene.sys which application uses ene.sys Mar 12, 2025 pm 01:25 PM

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

why won't driver asio.sys load why won't driver asio.sys load Mar 10, 2025 pm 07:58 PM

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda

How do I use the Group Policy Editor (gpedit.msc)? How do I use the Group Policy Editor (gpedit.msc)? Mar 21, 2025 pm 07:48 PM

The article explains how to use the Group Policy Editor (gpedit.msc) in Windows for managing system settings, highlighting common configurations and troubleshooting methods. It notes that gpedit.msc is unavailable in Windows Home editions, suggesting

How do I change the default app for a file type? How do I change the default app for a file type? Mar 21, 2025 pm 07:48 PM

Article discusses changing default apps for file types on Windows, including reverting and bulk changes. Main issue: no built-in bulk change option.

See all articles