🔒 Closed HOW TO SEARCH IN VB.NET USING DATAGRIDVIEW AND TEXTBOX

Status
Not open for further replies.

clynnekent

Forum Guru
Good day po sa lahat baka may makatulong sakin dito. Pano po mag search ng data galing sa database using datagridview and textbox. May ginawa kasi akong code pero di sya na wo work.Please help naman kung ano mali sa code ko.

Code :
databaseconnection.conn()
cn.Open()
Dim i As Integer
DataGridView1.Rows.Clear()



cmd = New OleDbCommand
cmd = New OleDbCommand("Select * from tblemprecord where Employee_lname like '%" & TextBox1.Text & "%' OR Employee_empid like '%" & TextBox1.Text & "%' OR Employee_fname like '%" & TextBox1.Text & "%'", cn)
cmd.Connection = cn
Using dtr = cmd.ExecuteReader()
If dtr.HasRows Then

While dtr.Read
i += 1
DataGridView1.Rows.Add(i, dtr.Item("Employee_id").ToString, dtr.Item("Employee_fname").ToString, dtr.Item("Employee_lname").ToString, dtr.Item("Employee_mname").ToString, dtr.Item("Employee_startdate").ToString, dtr.Item("Employee_gender").ToString, dtr.Item("Employee_employmentstatus").ToString, dtr.Item("Employee_designatory").ToString, dtr.Item("Employee_department").ToString)
End While

End If
End Using
cn.Close()

Gusto ko sana pag type ko sa textbox ex: nag type ako nang "A" lahat nang nasimula sa letter A sa datagridview makikita. Ganun lang po. Nagtataka lang ako bakit di ako maka search dyan. Sa mga magagaling na IT dyan pa help naman.

clynnekent
 
I already solved it thank you for reply guys.

This is the correct answer.

databaseconnection.conn()
cn.Open()
Dim i As Integer
DataGridView1.Rows.Clear()



cmd = New OleDbCommand
cmd = New OleDbCommand("Select * from tblemprecord where Employee_lname like '%" & TextBox1.Text & "%' OR Employee_id like '%" & TextBox1.Text & "%' OR Employee_fname like '%" & TextBox1.Text & "%'", cn)
cmd.Connection = cn
Using dtr = cmd.ExecuteReader()
If dtr.HasRows Then

While dtr.Read
i += 1
DataGridView1.Rows.Add(i, dtr.Item("Employee_id").ToString, dtr.Item("Employee_fname").ToString, dtr.Item("Employee_lname").ToString, dtr.Item("Employee_mname").ToString, dtr.Item("Employee_startdate").ToString, dtr.Item("Employee_gender").ToString, dtr.Item("Employee_employmentstatus").ToString, dtr.Item("Employee_designatory").ToString, dtr.Item("Employee_department").ToString)
End While

End If
End Using
cn.Close()

The problem my database and my code are not the same.
 
Sub searchrecord()
Try
dgView.Rows.Clear()
cn.Close()
cn.Open()
cm = New MySqlCommand("SELECT * from tblsubleader WHERE name like '%" & txtSearch.Text & "%' ORDER BY name ASC LIMIT 150", cn)
dr = cm.ExecuteReader
While dr.Read
dgView.Rows.Add(dr.Item("sl_id").ToString, dr.Item("voters_id").ToString, dr.Item("name").ToString, dr.Item("bar_name").ToString, dr.Item("purok").ToString, dr.Item("cluspre").ToString, dr.Item("preno").ToString, dr.Item("seqno").ToString)
End While
dr.Close()
dgView.ClearSelection()
Catch ex As Exception
cn.Close()
MessageBox.Show(ex.Message, _title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
 
Status
Not open for further replies.

About this Thread

  • 7
    Replies
  • 1K
    Views
  • 5
    Participants
Last reply from:
Vanexus

Trending Topics

Online now

Members online
1,088
Guests online
7,963
Total visitors
9,051

Forum statistics

Threads
2,354,257
Posts
29,382,932
Members
1,079,394
Latest member
vhenz
Back
Top