Private Sub txtsearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearch.KeyDown
If e.KeyCode = Keys.Enter Then
Dim s, s1 As String
If rbtid.Checked = True Then
s = "where Emp_ID ='" & txtsearch.Text & "'"
ElseIf rbtname.Checked = True Then
s = "where Emp_name like '" & txtsearch.Text & "%"
End If
s1 = "select * from Employee "
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
da = New SqlDataAdapter(s1, cn)
ds = New DataSet
da.Fill(ds, "emp")
With ds.Tables("emp")
If .Rows.Count <> 0 Then
txtid.Text = .Rows(0).Item("Emp_ID").ToString
txtname.Text = .Rows(0).Item("Emp_name").ToString
txtL.Text = .Rows(0).Item("Emp_last").ToString
txtAdd.Text = .Rows(0).Item("Emp_Add").ToString
txttel.Text = .Rows(0).Item("Emp_tel").ToString
txtUsername.Text = .Rows(0).Item("username").ToString
txtPass.Text = .Rows(0).Item("password").ToString
Else
MessageBox.Show("ไม่พบข้อมูล")
End If
End With
cn.Close()
End If
End Sub
นี่คือโค้ที่เขียนลงไปค่ะ จากการดูแล้วน่าจะเกิดตรง
Code (VB.NET)
If e.KeyCode = Keys.Enter Then
Dim s, s1 As String
If rbtid.Checked = True Then
s = "where Emp_ID ='" & txtsearch.Text & "'"
ElseIf rbtname.Checked = True Then
s = "where Emp_name like '" & txtsearch.Text & "%"
End If