MS Access Query Database in VB 2008

I added the Access database as a data source in VB 2008. I want to query this database and use this information in various ways throughout the program. For example, there is an Employee table with the names of employees. I have a summary in my form that I want to show to all employees. So I want to query the database for all the rows in the Employee table and add them to the combo box when I go.

I am familiar with the SQL syntax, so I do not ask how to write the query itself, but how to get the lines in VB code (in fact, imitate php mysql_fetch_assoc and mysql_connect)

Thank!

Edit: Also, I want to know if I can query the database if I don't add it as a data source (if I know the name of the database path)

+3
source share
1 answer

You use classes in the namespace System.Data.OleDbto query access databases:

Using cn As New OleDbConnection("connection string here"), _
      cmd As New OleDbCommand("SELECT query with ? parameter here", cn)

    cmd.Parameters.Add("?", OleDbType.Int).Value = 1234

    MyCombobox.DataSource = cmd.ExecuteReader()
End Using
+4
source

Source: https://habr.com/ru/post/1747565/


All Articles