how can i populate listview from database? If the user search for a particular column (ex.Employee) then the output will be on the listview.

Attachments 1.png 16.1 KB

" This Code Will Work Mr.khentz create your database table name as emp1 and use datagridview to list your selection , post me if anything wrong good luck"

Imports System.Data.OleDb


"Code From : RajSoftCreation - SriLanka Nibm - R.H.H.D.Kumara"


Public Class Form1
Public con1 As New OleDbConnection
Public ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con1 = New OleDbConnection("provider = microsoft.jet.oledb.4.0;Data Source =<path of your DataBase>")
con1.Open()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim mdad As OleDbDataAdapter

If ComboBox1.SelectedIndex = 0 Then
ds.Clear()

mdad = New OleDbDataAdapter("select * from emp1 where Employee = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 1 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Workstation = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")

End If

If ComboBox1.SelectedIndex = 2 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Shift = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 3 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Computer_Name = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 4 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Asst_Tag = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 5 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Sercvise = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 6 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Local_Number = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If


DataGridView1.DataSource = ds
DataGridView1.DataMember = "emp1"
End Sub
End Class

Edited 5 Years Ago by harshadilup: n/a

" This Code Will Work Mr.khentz create your database table name as emp1 and use datagridview to list your selection , post me if anything wrong good luck"

Imports System.Data.OleDb


"Code From : RajSoftCreation - SriLanka Nibm - R.H.H.D.Kumara"


Public Class Form1
Public con1 As New OleDbConnection
Public ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con1 = New OleDbConnection("provider = microsoft.jet.oledb.4.0;Data Source =<path of your DataBase>")
con1.Open()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim mdad As OleDbDataAdapter

If ComboBox1.SelectedIndex = 0 Then
ds.Clear()

mdad = New OleDbDataAdapter("select * from emp1 where Employee = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 1 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Workstation = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")

End If

If ComboBox1.SelectedIndex = 2 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Shift = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 3 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Computer_Name = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 4 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Asst_Tag = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 5 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Sercvise = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If

If ComboBox1.SelectedIndex = 6 Then

ds.Clear()
mdad = New OleDbDataAdapter("select * from emp1 where Local_Number = @1st", con1)
mdad.SelectCommand.Parameters.AddWithValue("@1st", TextBox1.Text)
mdad.Fill(ds, "emp1")
End If


DataGridView1.DataSource = ds
DataGridView1.DataMember = "emp1"
End Sub
End Class

Attachments new0.jpg 26.37 KB new1.jpg 40.03 KB new2.jpg 32.66 KB new3.jpg 40.28 KB new5.jpg 31.93 KB

Thanks for this harshadilup, :)

I'm testing it right now. But I have questions,

New OleDbDataAdapter("select * from emp1 where Employee = @1st", con1)

in where Employee = @1st
Is Employee also the name of the field in my database base?
and how about @1st?What is the use of it?

This question has already been answered. Start a new discussion instead.