Private Sub SB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SB1.Click
Search_Record()
End Sub
Private Sub Search_Record()
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
Dim sSQL As String = String.Empty
'try catch block is used to catch the error
Try
'get connection string declared in the Module1.vb and assing it to conn variable
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL = "SELECT number_id,date_time,name_id,Firthname,Lastname,Birthday,sex,CH,GC, MOO_ID,A1,A2,B1,B2,B3,B4,C1,C2,D1,D2,D3,D4,E1,E2,E3,E4,E5,F1,G1,G2,G3,H1,H2,H3,H4,H5,H5,H6 FROM Geezer"
If Me.S1.Text = Me.S1.Text Then
sSQL = sSQL & " where Firthname like + '%" & Me.S1.Text & "%'"
End If
Select Case S3.SelectedItem
Case 0 = sSQL = sSQL & "where sex = ชาย'"
End Select
cmd.CommandText = sSQL
da.SelectCommand = cmd
da.Fill(dt)
Me.GeezerDataGridView.DataSource = dt
If dt.Rows.Count = 0 Then
MsgBox("No record found!")
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub
End Class
อันนี้ภาพในหน้างานครับ
Tag : .NET, Ms Access, VBScript, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
If Me.S1.Text = Me.S1.Text Then
sSQL = sSQL & " where Firthname like + '%" & Me.S1.Text & "%'"
End If
If Me.S1.Text = Me.S1.Text Then
sSQL = sSQL & " where Firthname like + '%" & Me.S1.Text & "%'"
End If
If Me.S1.Text = Me.S1.Text Then
sSQL = sSQL & " where Firthname like + '%" & Me.S1.Text & "%'"
End If
If Me.S1.Text = Me.S1.Text Then
sSQL = sSQL & " where Firthname like + '%" & Me.S1.Text & "%'"
End If
If Me.S3.Text = Me.S3.Text Then
sSQL = sSQL & " where sex like + '%" & Me.S3.Text & "%'"
If txtSearch.Text.Trim() = "" Then Exit Sub
sb.Remove(0, sb.Length())
sb.Append("SELECT * FROM Table")
Select Case cboSearch1.SelectedIndex
Case 0
sb.Append(" WHERE (EmpID=@EmpID)")
Case 1
sb.Append(" WHERE (FullName LIKE @FullName)")
End Select
sb.Append(" ORDER BY EmpID")
Dim sqlSearch As String
sqlSearch = sb.ToString()
dt = New DataTable()
With com
.Parameters.Clear()
Select Case cboSearch1.SelectedIndex
Case 0
.Parameters.Add("@EmpID", SqlDbType.NVarChar).Value = txtSearch.Text.Trim()
Case 1
.Parameters.Add("@FullName", SqlDbType.NVarChar).Value = "%" & txtSearch.Text.Trim() & "%"
End Select
.CommandText = sqlSearch
.CommandType = CommandType.Text
.Connection = Conn
dr = .ExecuteReader
If dr.HasRows Then
ClearBinding()
dt.Load(dr)
bn.BindingSource = bs
dgv.DataSource = dt
txtEmpID.DataBindings.Add("Text", bs, "EmpID")