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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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.

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

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.

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

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

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

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