รบกวนขอคำแนะนำทีครับ Select Date BETWEEN ลองเอา CODE ของเพื่อน ๆ ในนี้ไปแปลงดูแล้วก็ยังไม่ได้ครับ
เก็บข้อมูลเป็น Date Sql Server 2014 ครับ]
Code (VB.NET)
Private Sub runreport()
If cn.State = ConnectionState.Closed Then cn.Open()
If Checkday.Checked Then
Dim sql As String = "SELECT * FROM F_ree WHERE redate between '" & Format(D1.Value, "yyyy/mm/dd") & "' and '" & Format(D2.Value, "yyyy/mm/dd") & " ORDER BY redate ASC'"
Else
allday.Checked = True
End If
Dim adapter As New SqlDataAdapter()
Dim dataset As New DataSet()
adapter.Fill(dataset, "F_ree")
DR = cmd.ExecuteReader
Dataallbuy.Rows.Clear()
While (DR.Read() = True)
Dataallbuy.Rows.Add(DR(0), DR(1), DR(2), DR(3), DR(4))
End While
cn.Close()
End Sub
Dim sql As String = "SELECT * FROM F_ree WHERE redate between '" & String.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(D1.Value)) & "' and '" & string.Format("{0:dd-MMM-yyyy}", String.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(D2.Value)) & " ORDER BY redate ASC'"
Date :
2019-11-19 14:13:16
By :
mr.win
No. 2
Guest
ผมใช้วิธีนี้อยู่ครับ
Code (VB.NET)
SELECT * FROM F_ree WHERE redate between convert(datetime, '" & D1.Value.ToLongDateString & "',105) and convert(datetime, '" & D2.Value.ToLongDateString & "',105) ORDER BY redate ASC