sqlQuery ="select * from tbl_people where field_name like '%@search%' "
With myCommand
.CommandText = SQL
.Connection = conn
.Parameters.Clear()
.Parameters.AddWithValue("search", txtBox_name.Text)
End With
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim sqlQuery = "select * from tbl_people where id like '%@search%' "
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim sqltable As New DataTable
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
.Parameters.Clear()
.Parameters.AddWithValue("search", TextBox1.Text)
End With
lvpeople.Items.Clear()
For i = 0 To sqltable.Rows.Count - 1
With lvpeople
.Items.Add(sqltable.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(sqltable.Rows(i)("fname"))
.Add(sqltable.Rows(i)("lname"))
.Add(sqltable.Rows(i)("ide"))
End With
End With
Next
If TextBox1.Text = "" Then
loadpeople()
End If
If (TextBox1.Text).Length < 13 Then
Label2.Text = "ข้อมูลยังไม่ครบ 10 ตัว"
Label3.Text = "โปรดใส่รหัสนักศึกษาให้ครบถ้วน และถูกต้อง"
End If
If (TextBox1.Text).Length < 1 Then
Label2.Text = ""
Label3.Text = ""
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If (TextBox1.Text).Length < 13 Then
Label2.Text = "ข้อมูลยังไม่ครบ 10 ตัว"
Label3.Text = "โปรดใส่รหัสนักศึกษาให้ครบถ้วน และถูกต้อง"
else If (TextBox1.Text).Length < 1 Then
Label2.Text = ""
Label3.Text = ""
else
loadpeople()
End If
End Sub
public sub loadpeople()
Dim sqlQuery = "select * from tbl_people where id like '%@search%' "
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim sqltable As New DataTable
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
.Parameters.Clear()
.Parameters.AddWithValue("search", TextBox1.Text)
End With
With sqlAdapter
.SelectCommand =sqlCommand
.Fill(sqltable )
End With
lvpeople.Items.Clear()
For i = 0 To sqltable.Rows.Count - 1
With lvpeople
.Items.Add(sqltable.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(sqltable.Rows(i)("fname"))
.Add(sqltable.Rows(i)("lname"))
.Add(sqltable.Rows(i)("ide"))
End With
End With
Next
end sub
Imports MySql.Data.MySqlClient
Public Class Frmsea
Public sConnection As New MySqlConnection
Private Sub Formsea_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If sConnection.State = ConnectionState.Closed Then
sConnection.ConnectionString = "SERVER = localhost; USERID=root; PASSWORD=123456; DATABASE=attc;"
End If
TextBox1.MaxLength = 13
loadpeople()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim sqlQuery = "select * from tbl_people where id like '%@search%' "
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim sqltable As New DataTable
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
.Parameters.Clear()
.Parameters.AddWithValue("search", TextBox1.Text)
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(sqltable)
End With
lvpeople.Items.Clear()
For i = 0 To sqltable.Rows.Count - 1
With lvpeople
.Items.Add(sqltable.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(sqltable.Rows(i)("fname"))
.Add(sqltable.Rows(i)("lname"))
.Add(sqltable.Rows(i)("ide"))
End With
End With
Next
If TextBox1.Text = "" Then
loadpeople()
End If
If (TextBox1.Text).Length < 13 Then
Label2.Text = "ข้อมูลยังไม่ครบ 10 ตัว"
Label3.Text = "โปรดใส่รหัสนักศึกษาให้ครบถ้วน และถูกต้อง"
End If
If (TextBox1.Text).Length < 1 Then
Label2.Text = ""
Label3.Text = ""
End If
End Sub
Public Sub loadpeople()
Dim sqlQuery As String = "SELECT * FROM tbl_people "
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim TABLE As New DataTable
Dim i As Integer
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(TABLE)
End With
'แก้ไขสำหรับหน้าข้อมูล
lvpeople.Items.Clear()
For i = 0 To TABLE.Rows.Count - 1
With lvpeople
.Items.Add(TABLE.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("fname"))
.Add(TABLE.Rows(i)("lname"))
.Add(TABLE.Rows(i)("ide"))
End With
End With
Next
End Sub
End Class
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim sqlQuery As String = "select * FROM tbl_people WHERE id = '" & TextBox1.Text & "'"
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim sqltable As New DataTable
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(sqltable)
End With
lvpeople.Items.Clear()
For i = 0 To sqltable.Rows.Count - 1
With lvpeople
.Items.Add(sqltable.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(sqltable.Rows(i)("fname"))
.Add(sqltable.Rows(i)("lname"))
.Add(sqltable.Rows(i)("ide"))
End With
End With
Next
If TextBox1.Text = "" Then
loadpeople()
End If
If (TextBox1.Text).Length < 13 Then
Label2.Text = "ข้อมูลยังไม่ครบ 10 ตัว"
Label3.Text = "โปรดใส่รหัสนักศึกษาให้ครบถ้วน และถูกต้อง"
End If
If (TextBox1.Text).Length < 1 Then
Label2.Text = ""
Label3.Text = ""
End If
End Sub
Private Sub lvpeople_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvpeople.SelectedIndexChanged
idue = lvpeople.SelectedItems(0).Text
End Sub