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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

If you suspect your hard drive encounters issues, you can check the drive for errors on Windows 7. This php.cn post talks about fixdisk Windows 7. You can follow the guide to check the hard drive for errors on Windows 7.

Windows X-Lite Optimum 11 23H2 Home or Optimum 11 Pro could be your option if you need a custom lite system based on Windows 11 23H2. Go on reading and php.cn will show you how to download Optimum 11 23H2 ISO and install Pro or Home on your PC.

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

Tips and Suggestions Notifications is a new design of Windows 11. It will give you suggestions and tips on some new features. But some of you may be bothered by the popup tips. You can read this post from php.cn to learn how to turn off tips and sugg

You must be familiar with the Windows P shortcut if you have more than one monitor. However, the Windows P not working properly might happen occasionally. If you are facing this problem, this post from php.cn can help you indeed.

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.
