i'm trying to write a small thing with vb.net using visual studio 2008
and i am new to VB and the .net framework
however after some google'ng i managed to understand few stuff and i wrote a small example where i have a button, text box and a DataGridView
the user enter a word in the text box and click the button
the program search the database basing on the user word
however it is not working, can anyone help me.
this is the code
Code: Select all
Imports System.Data.OleDb
Public Class Form1
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim query As String
Dim kword As String
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentClick
kword = txtSearch.Text
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\db.accdb;User Id=admin;Password=;")
query = "SELECT * FROM Table1 where customerID LIKE " + kword + "%"
cn.Open()
MsgBox("DB cnx opened")
cmd = New OleDbCommand(query, cn)
dr = cmd.ExecuteReader
dgv.DataSource = dr
dr.Close()
cn.Close()
End Sub
End Class