Private Sub txt_searchbill_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_searchbill.TextChanged
sql = "select claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend where claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%'"
datagrid_bill.DataSource = cmd_excuteDataTable()
chang_datagrid_column()
End Sub
Tag : .NET, Ms SQL Server 2008, Ms SQL Server 2012, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)
Date :
2018-02-20 11:32:41
By :
ชรินทร์
View :
1158
Reply :
12
No. 1
Guest
TextChanged ไม่น่าเหมาะนะครับ
น่าจะใช้ keyup แล้วดักจับ enter น่าจะดีกว่า
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
If Not String.IsNullOrEmpty(TextBox1.Text) Then
'ค้นหา
End If
End If
End Sub
แบบที่ 2 เมื่อพิมพ์เสร็จ Code (VB.NET)
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
If Not String.IsNullOrEmpty(TextBox1.Text) Then
'ค้นหา
End If
End Sub
นี้โค๊ดที่ผมเขียนไว้ ต้องแก้ไขตรงไหนครับ หรือเขียนเพิ่มเติมอะรัยบ้างครับ ช่วยแนะนำหรือขอตัวอย่างได้มั้ยครับ หรือต้องเพิ่มตรง where หรือป่าวครับ
Private Sub txt_searchbill_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_searchbill.TextChanged
sql = "select claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend where claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%'"
datagrid_bill.DataSource = cmd_excuteDataTable()
End Sub
sql = "select claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend where claimsend_status = "1" claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%'"
datagrid_bill.DataSource = cmd_excuteDataTable()
อันนี้ที่เขียนเพิ่มครับ
If e.KeyCode = Keys.Enter Then
If Not String.IsNullOrEmpty(txt_searchbill.Text) Then
sql = "select claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend where claimsend_status='1' and claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%'"
datagrid_bill.DataSource = cmd_excuteDataTable()
chang_datagrid_column()
lbl_counw.Text = datagrid_bill.Rows.Count
End If
End If
SELECT claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend WHERE claimsend_status='1'
AND (claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%'")
ได้แล้วครับอาจารย์ TOR เพิ่ม () แบบที่อาจารย์ pakyaudio บอกครับ ได้เลยครับ ขอบคุณสำหรับทุกคำช่วยเหลือมากๆเลยนะครับ
sql = "select claimsend_id, claimsend_idcus, claimsend_name, claimsend_address, claimsend_transpp, claimsend_billid, claimsend_datein, claimsend_dateout, claimsend_totals from claimdetelsend where claimsend_status='1' and (claimsend_id like '%" & txt_searchbill.Text &
"%' or claimsend_idcus like '%" & txt_searchbill.Text & "%' or claimsend_name like '%" & txt_searchbill.Text & "%' or claimsend_address like '%" & txt_searchbill.Text & "%' or claimsend_transpp like '%" & txt_searchbill.Text &
"%' or claimsend_billid like '%" & txt_searchbill.Text & "%' or claimsend_datein like '%" & txt_searchbill.Text & "%' or claimsend_dateout like '%" & txt_searchbill.Text & "%' or claimsend_totals like '%" & txt_searchbill.Text & "%')"
datagrid_bill.DataSource = cmd_excuteDataTable()