Hello,
Can anyone help with my problem. I am trying to create a search facility that will search from car makes in a combo box using an Access database, however i have got stuck. I have populated te combo box but when i click search i receive the following error.
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
Can anyone tell me what i do to overcome this. The error is related to the BtnSearch code which i have made bold and italic. The error is created specfically on the OleDbDataAdapter1.Fill(DataSet1)line. Although i have used the same code in the form load section with no errors.
I understand very little of
VB.NET as i have only just started using it.
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Conn As New OleDb.OleDbConnection
Dim Comm As New OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
End Sub
Private Sub getData()
DataSet1.Clear()
OleDbDataAdapter1.Fill(DataSet1)
DataGrid1.SetDataBinding(DataSet1, "T_Vehicle")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
getData()
fillCombo()
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage
End Sub
Private Sub OleDbDataAdapter1_RowUpdated(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles OleDbDataAdapter1.RowUpdated
End Sub
Private Sub fillCombo()
Try
makeConn(Conn)
Comm.CommandText = "SELECT Distinct Make FROM T_Vehicle; "
Comm.Connection = Conn
Reader = Comm.ExecuteReader(CommandBehavior.SequentialAcces s)
Do While Reader.Read
ComboMake.Items.Add(Reader.GetValue(0).ToString)
Loop
Catch grE As Exception
MsgBox(grE.Message)
Finally
Reader.Close()
Conn.Close()
End Try
End Sub
Private Sub makeConn(ByVal newConn As OleDb.OleDbConnection)
newConn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"User ID=Admin;" & _
"Data Source=F:\VehFinda.mdb;"
newConn.Open()
End Sub
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
OleDbDataAdapter1.SelectCommand.CommandText = _
"SELECT Make FROM T_Vehicle " & _
"WHERE Make = " & (ComboMake.Text)
DataSet1.Clear()
OleDbDataAdapter1.Fill(DataSet1)
DataGrid1.SetDataBinding(DataSet1, "T_Vehicle")
End Sub
Private Sub BtnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBrowse.Click
OleDbDataAdapter1.SelectCommand.CommandText = _
"Select * From T_Vehicle"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboMake.SelectedIndexChanged
End Sub
End Class
Thank you
Harvey
HAS