Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > รบกวนแนะนำหรือ ขอโค๊ดค้นหาแบบมีเงื่อนไขใน texbox หน่อยครับ



 

รบกวนแนะนำหรือ ขอโค๊ดค้นหาแบบมีเงื่อนไขใน texbox หน่อยครับ

 



Topic : 130344



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์




รบกวนแนะนำทีครับ หรือขอโค๊ดก็ได้ครับ ผมต้องการค้นหาจาก texbox แบบมีเงื่อนไข ว่าในฐานข้อมูลในคอลั้ม claimsend_status เฉพาะที่เป็นตัวเลข 1 เท่านั้นอ่ะครับ ต้องเขียนแบบไหนครับ ที่ผมเขียนมาเวลาค้นหา ข้อมูลมันมาทั้งหมดเลยครับ ขอบคุณครับ

อันนี้โค๊ดที่ผมเขียนไว้ครับ ต้องแก้ไขตรงไหน หรือเพิ่มเติมอะรัยช่วยบอกหน่อยครับ

Code (VB.NET)
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


2325

85963

45214



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)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-02-20 11:32:41 By : ชรินทร์ View : 1082 Reply : 12
 

 

No. 1

Guest


TextChanged ไม่น่าเหมาะนะครับ
น่าจะใช้ keyup แล้วดักจับ enter น่าจะดีกว่า






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-20 12:22:21 By : Dr.K
 


 

No. 2



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : Dr.K เมื่อวันที่ 2018-02-20 12:22:21
รายละเอียดของการตอบ ::
มีตัวอย่างมั้ยครับ ยังไม่ค่อยเข้าใจอ่ะครับ พอดีพึ่งหัดเขียนครับ ขอบคุณครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-20 12:38:13 By : ชรินทร์
 

 

No. 3



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ลองแบบนี้นะครับ
แบบที่ 1. กด Enter เพื่อค้นหา หรือ กด tab
Code (VB.NET)
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


ลองเอาไปเล่นดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-20 14:57:17 By : lamaka.tor
 


 

No. 4



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : lamaka.tor เมื่อวันที่ 2018-02-20 14:57:17
รายละเอียดของการตอบ ::
ไม่ใช่ครับอาจารย์ TOR คือผมจะอธิบายยังงัยดีอ่ะ555 คือผมต้องการค้นหาข้อมูลในกริด เฉพาะที่โชวอยู่ครับ คือในฐานข้อมูลผมจะมีคอลั้ม สเตตัสด้วยครับ ถ้าสเตตัสเป็น เลข 1 ให้เอามาโชวที่กริดครับ แต่ถ้าสเตตัสเป็น 0 ไม่เอามาโชวในกริดครับ ก็คือสเตตัสเป็น 0 คืองานที่จบไปแล้วอ่ะครับ ไม่ต้องการค้นหาแล้วครับ แต่เวลาค้นหาจาก Texbox ข้อมูลที่จบไปแล้ว=ข้อมูลที่มีสเตตัสเป็น 0 มันจะขึ้นมารวมกับข้อมูลที่ยังไม่จบงาน=ข้อมูลที่มีสเตตัสเป็น 1 คือผมไม่ต้องให้มารวมกับข้อมูลที่ยังไม่จบงานตอนค้นหาอ่ะครับ ต้องเขียนโค๊ดแบบไหนอครับ

นี้โค๊ดที่ผมเขียนไว้ ต้องแก้ไขตรงไหนครับ หรือเขียนเพิ่มเติมอะรัยบ้างครับ ช่วยแนะนำหรือขอตัวอย่างได้มั้ยครับ หรือต้องเพิ่มตรง 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
123654

321456




ประวัติการแก้ไข
2018-02-21 09:46:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-21 09:41:24 By : ชรินทร์
 


 

No. 5



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 4 เขียนโดย : ชรินทร์ เมื่อวันที่ 2018-02-21 09:41:24
รายละเอียดของการตอบ ::
คือผมไม่ได้แตะที่ sql ครับ

แต่ผมจะบอกว่า TextChanged อาจจะมีปัญหา ครับ
ลองเปลี่ยนมาใช้ KeyDown หรือไม่ก็ Leave จะดีกว่าครับ

เพราะ TextChanged มันจะค้นหาทุกครั้งที่เรากด ซึ่งถ้าข้อมูลเยอะอาจจะค้างได้ครับ

ส่วน sql เราเราจะเจาะให้แคบลงควรใช้ And เพราะ or หมายถึงเอามารวมกันครับ

เช่น เลือกเอาแค่คนใส่เสื้อสีดำ และ กางเกงสีขาว จะได้แค่ คนใส่เสื้อสีดำ และ กางเกงสีขาว
แต่ถ้าบอกว่า คนใส่เสื้อสีดำ หรือ กางเกงสีขาว จะได้ คนใส่เสื้อสีดำ และ กางเกงสีขาว และ คนใส่เสื้อสีดำ และ กางเกงสีดำ สีเขียวฯลฯ มาด้วย เป็นต้นครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-21 10:59:52 By : lamaka.tor
 


 

No. 6



โพสกระทู้ ( 77 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

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()


เพิ่ม claimsend_status = "1" ครับ ไม่รู้ว่าถ้าสมการ เทอมแรก เป็นเท็จ มันจะข้าม like ทั้งหมดหรือเปล่า มีหลายเทอมเกิน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-21 19:43:49 By : nk4ever
 


 

No. 7



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 5 เขียนโดย : lamaka.tor เมื่อวันที่ 2018-02-21 10:59:52
รายละเอียดของการตอบ ::
เข้าใจแล้วครับอาจารย์ TOR ขอบคุณครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-22 11:36:19 By : ชรินทร์
 


 

No. 8



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 6 เขียนโดย : nk4ever เมื่อวันที่ 2018-02-21 19:43:49
รายละเอียดของการตอบ ::
ไม่ได้ครับ ลองเพิ่มแล้วครับ ผมลองค้นหา บิลที่มีสถานะ เป็น 0 ก็ยังเด้งขึ้นมาอยู่เลยครับ ผมต้องการไม่ให้สถานะบิลที่เป็น0 หรือเลขบิลที่จบงานไปแล้วจะต้องค้นหาไม่เจออ่ะครับ จะต้องค้นหาเจอเฉพาะเลขที่บิลที่มีสถานะเป็น 1 เท่านั้น หรือบิลที่ยังไม่จบงานอ่ะครับ

อันนี้ที่เขียนเพิ่มครับ
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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-22 11:49:57 By : ชรินทร์
 


 

No. 9



โพสกระทู้ ( 119 )
บทความ ( 3 )



สถานะออฟไลน์
Facebook

ลองอย่างนี้ดูครับ

Code (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 & "%'")


คือ หลัง AND ก็ใส่วงเล็บ like ไว้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-23 09:13:31 By : pakyaudio
 


 

No. 10



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

SQL ที่ต้องการใช่แบบนี้รึป่าวครับ
เพิ่ม claimsend_status = 1 ลงไปด้วย
Code (VB.NET)
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 & "%'" AND_
"claimsend_status = 1"

datagrid_bill.DataSource = cmd_excuteDataTable()
chang_datagrid_column()



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-23 11:58:10 By : lamaka.tor
 


 

No. 11



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 9 เขียนโดย : pakyaudio เมื่อวันที่ 2018-02-23 09:13:31
รายละเอียดของการตอบ ::
ได้แล้วครับ ขอบคุณมากเลยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-23 16:18:59 By : ชรินทร์
 


 

No. 12



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 10 เขียนโดย : lamaka.tor เมื่อวันที่ 2018-02-23 11:58:10
รายละเอียดของการตอบ ::
ได้แล้วครับอาจารย์ 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()

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-02-23 16:23:51 By : ชรินทร์
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนแนะนำหรือ ขอโค๊ดค้นหาแบบมีเงื่อนไขใน texbox หน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่