Imports System.Data.SqlClient
Public Class Form7
Private Function search1() As DataTable
Dim query1 As String = "Select table1.id,table1.name1,table1.tel," & _
"sports.sport_name,hobbies.hobby_name,countries.country from" & _
"(table1 inner join sports on table1.id_sport=sports.id)" & _
" inner join hobbies on table1.id_hobby=hobbies.id" & _
" inner join countries on table1.id_country=countries.id"
query1 &= " where name1 like '%' +@parm1+ '%' "
query1 &= " or name1 like '%' +@parm1+ '%' "
query1 &= " or tel like '%' +@parm1+ '%' "
query1 &= " or sport_name like '%' +@parm1+ '%' "
query1 &= " or hobby_name like '%' +@parm1+ '%' "
query1 &= " or country like '%' +@parm1+ '%' "
query1 &= " or @parm1= '' order by table1.id "
Dim conn As New SqlConnection("Data source=.;initial catalog=names;integrated security=true")
Dim cmd As New SqlCommand(query1, conn)
cmd.Parameters.AddWithValue("@parm1", TextBox1.Text.Trim())
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Return (dt)
End Function
Private Sub Form7_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DataGridView1.DataSource = Me.search1
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
DataGridView1.DataSource = Me.search1
End Sub
End Class
No comments:
Post a Comment