My code is:
System.Data.OleDb
Public Class Form1
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DBB.mdb;")
cn.Open()
cmd = New OleDbCommand("select * from TbA", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class
It works for a database without password. But for a database with password and the string:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DBB.mdb;Jet OLDB:Database Password=xxx"
I get an error: "Object reference not set to an instance of an object."
Where wrong?
Thanks!