Может кто-нибудь сказать мне, как мне решить эту ошибку.Ошибка: исключение NullReferenceException было необработанным - «Ссылка на объект не установлена для экземпляра объекта».Строка: Dim reader As OleDbDataReader = dbCommand.ExecuteReader () База данных: MS Access IDE: VB 2010 Express
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System
Public Class Form1
Dim dbConnection As OleDbConnection
Dim dbCommand As OleDbCommand
Dim strInsert As String
Dim dbDataAdapter As OleDbDataAdapter
Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source =atg.mdb"
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
dbConnection = New OleDbConnection(ConnectString) 'here I use the new keyword to initialize connection
dbConnection.Open()
Dim command As New OleDbCommand("SELECT XX FROM ABC", dbConnection) ' initialize command and pass query and open connection to its constructor
Dim reader As OleDbDataReader = dbCommand.ExecuteReader() 'ERROR IS HERE
Do While (reader.Read()) ' loop here until reader finish reading and add every row to the list box
ListBox1.BeginUpdate()
ListBox1.Items.Add(reader.Item("ABC"))
ListBox1.EndUpdate()
Loop
reader.Close()
dbConnection.Close()
End Sub
End Class