I need to know how to show my search item in a data grid? There is error in grid display part. Can you help me to solve it?
Imports System.Data.OleDb
Imports System.Text
Public Class mainpage
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim cn4 As OleDbConnection
Dim cmd4 As OleDbCommand
'Dim cn As OleDbConnection
'Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private PrintGrid As DataGridViewPaintParts
Dim con As New OleDb.OleDbConnection
Dim cmdOle As New OleDb.OleDbCommand
Dim dsOle As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim dtOle As New DataTable
Dim sql As String
Private Sub find_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles find.Click
Dim a As String
'Dim str As String
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\HARTI_RES_PRO.accdb;")
cn.Open()
Dim whrCond As StringBuilder
whrCond = New StringBuilder()
whrCond.Append(" where ")
'whrCond.Append("Source_Of_Funding LIKE '%" & ComboBox1.SelectedValue & "%'")
If ComboBox1.SelectedValue = "Researcher's Name" Then
whrCond.Append(" Researcher LIKE '%" & TextBox1.Text & "%'")
ElseIf ComboBox1.SelectedValue = "Project title " Then
whrCond.Append(" Project_title LIKE '%" & TextBox1.Text & "%'")
ElseIf ComboBox1.Text = "Project code" Then
whrCond.Append(" Code LIKE '%" & TextBox1.Text & "%'")
'str = "select * from QAruni where Code LIKE '%" & TextBox1.Text & "%'"
ElseIf ComboBox1.SelectedValue = "Division" Then
whrCond.Append(" Division LIKE '%" & TextBox1.Text & "%'")
ElseIf ComboBox1.SelectedValue = "Co-researchers" Then
whrCond.Append(" Co_Researchers LIKE '%" & TextBox1.Text & "%'")
ElseIf ComboBox1.SelectedValue = "Source of funding" Then
whrCond.Append(" Source_of_funding LIKE '%" & TextBox1.Text & "%'")
End If
a = "select * from QAruni" & whrCond.ToString()
cmd = New OleDbCommand("select * from QAruni" & whrCond.ToString(), cn)
'MsgBox(a)
'dr = cmd.ExecuteReader
'While dr.Read()
'End While
da.SelectCommand = cmdOle
da.Fill(dsOle, "QAruni") ' This Table name
DataGridView1.DataSource = dsOle
DataGridView1.DataMember = "QAruni" ' This Table name
DataGridView1.ReadOnly = True[/COLOR]
cn.Close()
End sub