 |
|
หากต้องการค้นหาข้อมูลจากคอลั่มเดียวกัน โดยใช้ textbox 2 ตัวต้องใช้โค๊ดแบบไหนครับ มือใหม่ |
|
 |
|
|
 |
 |
|
ต้องการค้นหา 2 เงื่อนไข จากคอลั่มเดียวกัน โดยใช้ txt เป็นเงื่อนไขที่ 1 และ txt1 เป็นเงื่อนไขที่ 2

อันนี้โค๊ดครับผมลองแบบนี้แล้วค้นหาไม่เจออ่ะครับ ต้องการใช้ txt กับ txt1 ค้นหาร่วมกันอ่ะครับ
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
sql = String.Format("select idcus,docid,dgetreport,names,adtambon,adaumper,adcity,teamasset1,teamasset2,dsentreport,statusqc from customer where dgetreport Between '" & dtp1.Value.ToString("yyyy-MM-dd") & "' AND '" & dtp2.Value.ToString("yyyy-MM-dd") & "' AND statusqc like '%" & txt1.Text & "%' and customer.statusqc = '" & txt.Text & "' ")
dgv1.DataSource = cmd_dataTable()
refresh_all_data_user()
dgv1.Columns(0).Width = 80
dgv1.Columns(1).Width = 150
End Sub
Tag : Ms SQL Server 2008, VB.NET, VS 2010 (.NET 4.x)
|
ประวัติการแก้ไข 2018-10-08 19:31:01 2018-10-08 19:34:32 2018-10-08 20:00:56
|
 |
 |
 |
 |
Date :
2018-10-08 19:07:08 |
By :
winamp |
View :
968 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
debug sql เอา value ที่ได้ตรวจเช็คด้วยตา แล้ว นำไปคิวรี่ด้วย ssms ดู ก่อนครับ
เช็คดูว่าผิดที่ sql statement หรือ script vb กันแน่
|
 |
 |
 |
 |
Date :
2018-10-08 19:30:52 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้ว ค้นหา text อันเดียว มันแสดง วันที่ อยู่ใน ระยะเวลที่ต้องการด้วยหรือเปล่า
และกำหนด data type ของวันที่ ไว้แบบไหน
|
 |
 |
 |
 |
Date :
2018-10-08 20:16:51 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าตรงนี้มันย้อนแยงกันแปลกๆ ตกลงจะหาแค่บางส่วน หรือหาเฉพาะเจาะจงครับ
Code (VB.NET)
statusqc like '%" & txt1.Text & "%' and customer.statusqc = '" & txt.Text & "' "
|
 |
 |
 |
 |
Date :
2018-10-08 20:32:50 |
By :
realizejoke |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แสดงทั้งสองเงื่อนไข ต้องใช้ or
|
 |
 |
 |
 |
Date :
2018-10-08 22:12:18 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 7 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-10-08 22:12:18
รายละเอียดของการตอบ ::
Code (VB.NET)
ลองแล้วค้นเจอครับ ใช้โค๊ดตัวล่างแล้วเจอ แต่วันที่ตัวที่ค้นหามันดันเพี้ยน เห้อ
Code (VB.NET)
sql = String.Format("select idcus,docid,dgetreport,names,adtambon,adaumper,adcity,teamasset1,teamasset2,dsentreport,statusqc from customer where statusqc like '%" & txt.Text & "%' or statusqc like '%" & txt1.Text & "%' AND dgetreport Between '" & dtp1.Value.ToString("yyyy-MM-dd") & "' AND '" & dtp2.Value.ToString("yyyy-MM-dd") & "' ")
dgv1.DataSource = cmd_dataTable()
|
 |
 |
 |
 |
Date :
2018-10-08 23:55:46 |
By :
winamp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาวงเล็บ ครอบ condition แยก priprity .ให้ชัดเจนครับ
ยังไงเอา result ของ sql statement มาลงให้ดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2018-10-09 06:48:16 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|