Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tbxSearch.Text.Trim() = "" Then
MsgBox("กรุณาระบุชื่อที่ต้องการค้นหา", MsgBoxStyle.Information)
Exit Sub
End If
Dim sb As New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT Passenger_ID,Name,M_name,L_name,Mobile,E-mail From Passenger")
sb.Append(" Where (Name like '%" & tbxSearch.Text & "%')")
Dim sql As String = sb.ToString()
Dim com As New OleDbCommand()
Dim dr As OleDbDataReader
Dim dt As DataTable
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
'.Parameters.Clear()
'.Parameters.Add("Name", OleDbType.VarChar).Value = tbxSearch.Text.Trim()
dr = ExecuteReader()
End With
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
End If
dgvPassenger.DataSource = dt.Rows(0).Item("Name").ToString
End Sub
ช่วยดูให้หน่อยค่ะ มันผิดตรงไหน ทำไม dr = ExecuteReader() มัน error ตรง ExecuteReader
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
'.Parameters.Clear()
'.Parameters.Add("Name", OleDbType.VarChar).Value = tbxSearch.Text.Trim()
.ExecuteReader()
End With
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If tbxSearch.Text.Trim() = "" Then
MsgBox("กรุณาระบุชื่อที่ต้องการค้นหา", MsgBoxStyle.Information)
Exit Sub
End If
Dim sb As New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT Passenger_ID,Name,M_name,L_name,Mobile,E-mail From Passenger")
sb.Append(" Where (Name like '%" & tbxSearch.Text & "%')")
Dim sql As String = sb.ToString()
Dim com As New OleDbCommand()
Dim dr As OleDbDataReader
Dim dt As DataTable
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
'.Parameters.Clear()
'.Parameters.Add("Name", OleDbType.VarChar).Value = tbxSearch.Text.Trim()
dr = .ExecuteReader()
End With
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
End If
dgvPassenger.DataSource = dt.Rows(0).Item("Name").ToString
Catch ex As Exception
Messagebox.Show(ex.Message)
End Try
End Sub
Dim dr As OleDbDataReader
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
'.Parameters.Clear()
'.Parameters.Add("Name", OleDbType.VarChar).Value = tbxSearch.Text.Trim()
End With
dr = com.ExecuteReader()
If tbxSearch.Text.Trim() = "" Then
MsgBox("กรุณาระบุชื่อที่ต้องการค้นหา", MsgBoxStyle.Information)
Exit Sub
End If
Dim sb As New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT Passenger_ID,Name,M_name,L_name,Mobile,E-mail From Passenger")
sb.Append(" Where (Name LIKE @FindData")
Dim sql As String = sb.ToString()
Dim com As New OleDbCommand()
Dim dr As OleDbDataReader
Dim dt As DataTable
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
.Parameters.Clear()
.Parameters.Add("@FindData", OleDbType.VarChar).Value = "%" & tbxSearch.Text.Trim() & "%"
dr = .ExecuteReader()
End With
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
dgvPassenger.DataSource = dt.Rows(0).Item("Name").ToString
End If
End Sub
Try
If tbxSearch.Text.Trim() = "" Then
MsgBox("กรุณาระบุชื่อที่ต้องการค้นหา", MsgBoxStyle.Information)
Exit Sub
End If
Dim sb As New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT * From Passenger")
sb.Append(" Where (Name like '%" & tbxSearch.Text & "%')")
Dim sql As String = sb.ToString()
Dim com As New OleDbCommand()
Dim dr As OleDbDataReader
Dim dt As DataTable
With com
.CommandType = CommandType.Text
.CommandText = sql
.Connection = Conn
End With
dr = com.ExecuteReader()
If dr.HasRows Then
dt = New DataTable()
dt.Load(dr)
Else
MsgBox("ไม่มีข้อมูล", MsgBoxStyle.Critical, "ผลการทำงาน")
End If
dgvPassenger.DataSource = dt.Rows(0).Item("Name").ToString
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Private Sub btnfind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfind.Click
If MsgBox("คุณต้องการค้นหาข้อมูลใช่หรือไม่ ?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "ค้นหาข้อมูล") = MsgBoxResult.Ok Then
Try
ds.Tables.Clear()
Dim ra As String = ""
If RadioButton1.Checked Then
ra = "cusid"
End If
If RadioButton2.Checked Then
ra = "cusname"
End If
If TextBox4.Text = "" Then
MsgBox("กรุณากรอกข้อมูลที่ต้องการค้นหา", MsgBoxStyle.Information)
Else
Dim sql As String = "Select*from customer where " & ra & " like '" & TextBox4.Text & "%'"
da = New OleDbDataAdapter(sql, Conn)
da.Fill(ds, "customer")
dgv1.DataSource = ds.Tables("customer")
TextBox4.Clear()
End If
If dgv1.DataSource = "" Then
MsgBox("iiii")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub