get the results of the query

AccessShell

Member
Joined
Jun 14, 2016
Messages
21
Programming Experience
10+
I finally figured out how to open a connection to the DB

VB.NET:
dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = " & "MyTable.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()

Now I leave the connection string open and go elsewhere in the code to read data from the DB.

VB.NET:
dim strSQL as string

strSql = "SELECT tblCategories,CategoryName FROM tblCategories"

Now I don't know how to actually get the results of the query.

Any help would be appreciated.

Thanks
 
Take a look at this for some code examples of common ADO.NET scenarios. There are also plenty of ADO.NET tutorials around that would cover the basics.

By the way, it's considered poor practice to open an ADO.NET connection and then leave it open. ADO.NET has been designed such that you should be opening a connection only when you need to use it and then closing it as soon as possible.

Also, while it's not wrong, that's a bit of a silly way to build a connection string. If you're going to break it up at all then I'd suggest using an OleDbConnectionStringBuilder. It increases clarity and reduces the likelihood of errors.
 
Back
Top