|  | 
	                
  
    |  |  
    | 
        
        รบกวนแนะนำหรือ ขอโค๊ดค้นหาแบบมีเงื่อนไขใน texbox หน่อยครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | รบกวนแนะนำทีครับ หรือขอโค๊ดก็ได้ครับ ผมต้องการค้นหาจาก 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
 
  
 
  
 
  
 
 
 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 :
                          1267 | Reply :
                          12 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | TextChanged ไม่น่าเหมาะนะครับ น่าจะใช้ keyup แล้วดักจับ enter น่าจะดีกว่า
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2018-02-20 12:22:21 | By :
                            Dr.K |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองแบบนี้นะครับ แบบที่ 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 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | 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 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  ตอบความคิดเห็นที่ : 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 :
                            ชรินทร์ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองอย่างนี้ดูครับ 
 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 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | 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 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 |  |