Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27344

Problems connecting to Access DB from VB.Net windows form

$
0
0
It's been many years since I have done this. I want to read an Access database table from my vb.net windows form. I'm sure I don't have the connection string correct but not sure how to fix it. here is my present connection string in the app.config:

<add name="MRIAccess" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\ShipLabel.accdb;Persist Security Info=False;" />

Here is my code to read the table:

Code:

Dim connStringAccess As String = ConfigurationManager.ConnectionStrings("MRIAccess").ConnectionString

Dim queryString As String = "SELECT * from [ShippingLabel] s; "

                        Using connection As New OdbcConnection(connStringAccess)

                            ' Create the Command and Parameter objects.
                            Dim command As New OdbcCommand(queryString, connection)
                         
                            Try
                                connection.Open()
                                Dim dataReader As OdbcDataReader = _
                                command.ExecuteReader()
                                Do While dataReader.Read()
                                    Console.WriteLine( _
                                        vbTab & "{0}" & vbTab & "{1}" & vbTab & "{2}", _
                                    dataReader(0), dataReader(1), dataReader(2))
                                Loop
                                dataReader.Close()

                            Catch ex As Exception
                                Console.WriteLine(ex.Message)
                            Finally
                                connection.Close()
                            End Try
                            Console.ReadLine()
                        End Using

I get this error:

{"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"}

What am I doing wrong?

Viewing all articles
Browse latest Browse all 27344

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>