Private Sub txt_find_KeyDown(sender As Object, e As KeyEventArgs) Handles txt_find.KeyDown
If txt_find.Text.Trim() = "" Then Exit Sub
If e.KeyCode = Keys.Enter Then
' Dim CurrentdoctorID = doctors.SelectedValue.ToString()
Dim ps = From p In db.doctors
Where (p.doc_name.Contains(txt_find.Text.Trim()) _
OrElse (p.doc_phone.Contains(txt_find.Text.Trim()))) _
AndAlso (p.doc_phone.Contains(txt_find.Text.Trim()))
Select New With {
.doc_id = p.doc_id,
.doc_name = p.doc_id,
.doc_phone = p.doc_phone
}
If ps.Count() > 0 Then
dgv_doc.DataSource = ps.ToList()
backtoform()
Else
dgv_doc.DataSource = Nothing
MessageBox.Show("เงื่อนไขที่คุณป้อน ไม่ตรงกับข้อมูลสินค้าที่มีอยู่ !!!", "ผลการค้นหา", MessageBoxButtons.OK)
txt_find.Focus()
txt_find.SelectAll()
ShowCustomers()
FormatDgv_doctor()
End If
End If
End Sub
Tag : .NET, Ms SQL Server 2012, LINQ, VB.NET, VS 2012 (.NET 4.x)
Dim ps = From p In db.doctors
Where (p.doc_name.Contains(txt_find.Text.Trim()) OrElse (p.doc_phone.Contains(txt_find.Text.Trim())))
Select New With {
.doc_id = p.doc_id,
.doc_name = p.doc_name,
.doc_phone = p.doc_phone }