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.

Recommended Answers

All 4 Replies

" 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

" 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

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?

thanks for this one dude..it's working.,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.