คือผมลองคิวรี่แบบนี้ มันก็ได้ นะครับแต่ปัญหาผมคือ แล้วถ้าจะกำหนดช่วงตามวันที่ ผมเลย เพิ่มคำสั่ง ตรวจสแบวันที่ ดูผลerror ครับ
strOleDb = "SELECT Sum((UnitPrice*Quantity)-Discount) AS sumcount FROM OrderEarlierDetails INNER JOIN OrderEarlierRoom ON OrderEarlierDetails.OrderID = OrderEarlierRoom.OrdersID"
Code (VB.NET)
Sub allcall()
Dim strOleDb As String
If RadioShowAll.Checked = True Then
DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = "MM/dd/yyyy"
DateTimePicker2.Format = DateTimePickerFormat.Custom
DateTimePicker2.CustomFormat = "MM/dd/yyyy"
' error ชุดนี้
strOleDb = "SELECT Sum((UnitPrice*Quantity)-Discount) AS sumcount FROM OrderEarlierDetails INNER JOIN OrderEarlierRoom ON OrderEarlierDetails.OrderID = OrderEarlierRoom.OrdersID where OrderEarlierRoom.DateEarlier <=" & DateTimePicker1.Value & " or OrderEarlierRoom.DateEarlier >= " & DateTimePicker2.Value & " order by OrderEarlierRoom.DateEarlier ASC"
Else
'ชุดนี้ผ่าน
strOleDb = "SELECT Sum((UnitPrice*Quantity)-Discount) AS sumcount FROM OrderEarlierDetails INNER JOIN OrderEarlierRoom ON OrderEarlierDetails.OrderID = OrderEarlierRoom.OrdersID"
End If
Dim objCmd, objCmd2 As New OleDbCommand
objCmd = New OleDbCommand(strOleDb, acsconn)
TextBox1.Text = objCmd.ExecuteScalar()
End Sub
strOleDb = "SELECT Sum((UnitPrice*Quantity)-Discount) AS sumcount FROM OrderEarlierDetails INNER JOIN OrderEarlierRoom ON OrderEarlierDetails.OrderID = OrderEarlierRoom.OrdersID where OrderEarlierRoom.DateEarlier <='" & DateTimePicker1.Value & "' or OrderEarlierRoom.DateEarlier >='" & DateTimePicker2.Value & "' order by OrderEarlierRoom.DateEarlier ASC"