รบกวนสอบถามอีกรอบครับ คือตอนนี้ผมสามารถทำปุ่ม next ได้แล้วแต่ปัญหามันติดตรงที่ว่า เวลากดnext มันแสดงผลการค้นหาตั้งแต่แรกโดยไม่ได้โฟกัสเฉพาะคำที่ค้นหา สามาถใช้คำสั่งใดได้บ้างครับ รบกวนด้วยครับCode (VB.NET)
Imports System.Data.OleDb
Imports System.IO
Public Class Search
Dim filename1 As String
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Dim sql As String = "select * from Table1"
Dim i As Integer
Dim len As Integer
Private Sub ShowData(ByVal CurrentRow)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("provider=Microsoft.ace.oledb.12.0;data source=\\10.66.15.200\NYKAPP\Database2.accdb")
Dim cmd As New OleDbCommand
con.Open()
cmd.Connection = con
da = New OleDbDataAdapter(sql, con)
da.Fill(ds, "database2")
If RadioButton1.Checked = True Then
cmd.CommandText = "select add_Firstname from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_firstname Like '%" & TextBox1.Text & "%'"
'filename1 = cmd.ExecuteScalar
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton2.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_lastname Like '%" & TextBox1.Text & "%'"
'filename1 = cmd.ExecuteScalar
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton3.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_nickname Like '%" & TextBox1.Text & "%'"
'filename1 = cmd.ExecuteScalar
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton4.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_department Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_department Like '%" & TextBox1.Text & "%'"
'filename1 = cmd.ExecuteScalar
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton5.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_position Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
' cmd.CommandText = "select add_pic from Table1 where add_position Like '%" & TextBox1.Text & "%'"
' filename1 = cmd.ExecuteScalar
' PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton6.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_extention Like '%" & TextBox1.Text & "%'"
'filename1 = cmd.ExecuteScalar
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
If RadioButton7.Checked = True Then
cmd.CommandText = "select add_firstname from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox3.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_lastname from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox4.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_nickname from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox6.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_department from Table1 where add_locatione Like '%" & TextBox1.Text & "%'"
TextBox7.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_position from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox8.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_extention from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox9.Text = cmd.ExecuteScalar
cmd.CommandText = "select add_location from Table1 where add_location Like '%" & TextBox1.Text & "%'"
TextBox10.Text = cmd.ExecuteScalar
'cmd.CommandText = "select add_pic from Table1 where add_location Like '%" & TextBox1.Text & "%'"
' filename1 = cmd.ExecuteScalar
' PictureBox1.Image = Image.FromFile(Application.StartupPath & "\Pic\" & filename1)
End If
con.Close()
End Sub
Private Sub Search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("provider=Microsoft.ace.oledb.12.0;data source=\\10.66.15.200\NYKAPP\Database2.accdb")
Dim cmd As New OleDbCommand
con.Open()
cmd.Connection = con
da = New OleDbDataAdapter(sql, con)
da.Fill(ds, "database2")
len = da.Fill(ds, "database2")
End Sub
Private Sub nav()
TextBox3.Text = ds.Tables("database2").Rows(i).Item(3)
TextBox4.Text = ds.Tables("database2").Rows(i).Item(4)
TextBox6.Text = ds.Tables("database2").Rows(i).Item(6)
TextBox7.Text = ds.Tables("database2").Rows(i).Item(7)
TextBox8.Text = ds.Tables("database2").Rows(i).Item(8)
TextBox9.Text = ds.Tables("database2").Rows(i).Item(9)
TextBox10.Text = ds.Tables("database2").Rows(i).Item(10)
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
Me.TextBox1.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox6.Text = ""
Me.TextBox7.Text = ""
Me.TextBox8.Text = ""
Me.TextBox9.Text = ""
Me.TextBox10.Text = ""
Me.PictureBox1.Image = Nothing
End Sub
Private Sub C_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C.Click
Me.TextBox1.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox6.Text = ""
Me.TextBox7.Text = ""
Me.TextBox8.Text = ""
Me.TextBox9.Text = ""
Me.TextBox10.Text = ""
Me.PictureBox1.Image = Nothing
Me.Hide()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If (i = 0) Then
MsgBox("")
Else
i = i - 1
nav()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (i = len - 1) Then
MsgBox("")
Else
i = i + 1
nav()
End If
End Sub
End Class
ยกตัวอย่างนะครับคือ ใน Database เรามี A Aa Abc B Bc เวลาเราค้นหาเช่นค้นหา ด้วยคีย์เวิดว่า A มันจะโชว์ A แบบนี้ใช่ป่ะครับ คือผมอยากให้เวลากด ปุ่ม next ให้มันเลื่อนหาต่ออย่างเช่นแล้วจะเจอคำว่า A - Aa -Abc แต่ปัจจุบันผมค้นหามันก็เจอ A แต่เวลากด next มัน แสดง A -Aa - Abc - B - Bc คือผมอยากให้มันเห็นแค่เฉพาะคำที่เราค้นหา ขอโทษด้วยครับมือใหม่จริงๆอาจมีบ้างคำให้สับสนบ้าง