Dim SqlString As String = " Select * from FOorder as A , DetailFOorder as B where A.FOorder_id=B.FOorder_id And A.FOorder_DateSentPD between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
Date :
2013-09-18 19:21:23
By :
ยิ้ม
No. 7
Guest
Dim connect As SqlConnection = getDriver()
Dim dd As String = DateTimePicker1.Value.Date.Day
Dim mm As String = DateTimePicker1.Value.Date.Month
Dim yy As String = DateTimePicker1.Value.Date.Year
Dim StringSearchDate As String = dd + "/" + mm + "/" + yy
Dim dd2 As String = DateTimePicker2.Value.Date.Day
Dim mm2 As String = DateTimePicker2.Value.Date.Month
Dim yy2 As String = DateTimePicker2.Value.Date.Year
Dim StringSearchDate2 As String = dd2 + "/" + mm2 + "/" + yy2
Dim SqlString As String = " Select * from FOorder as A , DetailFOorder as B where A.FOorder_id=B.FOorder_id And A.FOorder_DateSentPD between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
ข้อมูลที่จัดเก็บ Sql server เป็นชนิด varchar ค่ะ
Date :
2013-09-18 19:23:41
By :
ยิ้ม
No. 8
Guest
Quote:
#NO 5 sb ย่อมาจากอะไรครับ = System.Text.StringBuilder
ตัวอย่างการใช้งาน VB
Dim sb As New System.Text.StringBuilder()
ตัวอย่างการใช้งาน C#
System.Text.StringBuilder sb = new System.Text.StringBuilder();
[color=red]#NO6, 7 ข้อมูลที่จัดเก็บ Sql server เป็นชนิด varchar ค่ะ[/color]
สิ่งที่ผิดมหันต์และไร้ค่า ถ้า Field FOorder_DateSentPD คุณเก็บเป็น varchar
Code (VB.NET) จะทำงานไม่ถูกต้องในบางกรณี
Dim SqlString As String = " Select * from FOorder as A , DetailFOorder as B where A.FOorder_id=B.FOorder_id And A.FOorder_DateSentPD between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
เดิม
Dim dd As String = DateTimePicker1.Value.Date.Day
Dim mm As String = DateTimePicker1.Value.Date.Month
Dim yy As String = DateTimePicker1.Value.Date.Year
Dim StringSearchDate As String = dd + "/" + mm + "/" + yy
ต้องแก้ไขเป็น
Dim StringSearchDate As String = String.Format(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), "{0:yyyy/MM/dd}", DateTimePicker1.Value)
[x] CultureInfo Thailand = th-TH, English US = en-US
วิจารณ์แบบสนุกฯ รูปแบบการเขียนคำสั่ง Query แบบที่ 1. ANSI-89 Standard
Inner Join Code (SQL)
Select * from FOorder as A , DetailFOorder as B where A.FOorder_id=B.FOorder_id And A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
Left Join Code (SQL)
Select * from FOorder as A , DetailFOorder as B where A.FOorder_id *=B.FOorder_id And A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
Right Join Code (SQL)
Select * from FOorder as A , DetailFOorder as B where A.FOorder_id =* B.FOorder_id And A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
แบบที่ 2. ANSI-92 Standard Inner Join Code (SQL)
Select * from FOorder as A Inner Join DetailFOorder as B ON A.FOorder_id = B.FOorder_id
Where A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
Left Join Code (SQL)
Select * from FOorder as A Left Join DetailFOorder as B ON A.FOorder_id = B.FOorder_id
Where A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"
Right Join Code (SQL)
Select * from FOorder as A Right Join DetailFOorder as B ON A.FOorder_id = B.FOorder_id
Where A.FOorder_DateSentPD Between '" + StringSearchDate.ToString() + "' And '" + StringSearchDate2.ToString() + "' Order by A.FOorder_DateSentPD"