1,105,594 Community Members

Best way to connect to database

Member Avatar
Baradaran
Junior Poster
104 posts since Feb 2007
Reputation Points: 1 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

I am totally new to vb.net, still I am planning to try it for a project, in which there will be standalone machine using an access database to query and update different tables.

While in VB6 I was able to define recordsets using Microsoft.jet.oledb.4.0, in VB.net I have become a little confused.

I plan to define a global connection to the access database:

Dim TheConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0; data source=|DataDirectory|\office.mdb;Persist Security Info=True;Jet OLEDB:Database Password=1234")

Depending on what the user has selected, a sql command is created, e.g.

Dim SQL_CUSTOMERS As OleDbCommand = New OleDbCommand("SELECT * FROM CUSTOMERS;", TheConnection)

A list of customers can be filled as follows:

        Try
            TheConnection.Open()

            Dim reader As OleDbDataReader
            reader = SQL_CUSTOMERS.ExecuteReader()

            Do While reader.Read()
                lst_kunden.Items.Add(reader.Item("COMPANY"))
            Loop

            reader.Close()
            TheConnection.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

The question is:

I want to display a MsgBox if there are no data available. Also is there a way to define recordsets?

I appreciate your help.

Member Avatar
Baradaran
Junior Poster
104 posts since Feb 2007
Reputation Points: 1 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

What is best to use in VB NET in place of the VB6 adodb.recordset?

Google provided some links, in which I found a few tips.

Question Self-Answered as of 1 Year Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: