Hi to everyone!
I am new in programming and I'm making an application that can filter records on datagrid from the user's input in textbox..I tried this code that I also got here.. But I'm getting an error..please help me..thanks in advance..
ERROR MESSAGE:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Fill: SelectCommand.Connection property has not been initialized.
_____________________________________________________
Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim keywords As String = TextBox1.Text
Dim con As OleDbConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\addressbook1.mdb")
' Use wildcard
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM tblcontacts WHERE firstname Like '% " & keywords & " %', con ")
' or Where Filed1='" & keywords & "'
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet
myDA.Fill(myDataSet, "MyTable")
DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
End Sub