[操作疑難] SQL in VB - Search between two dates

本帖最後由 X-Engineer 於 2016-12-12 15:45 編輯

結果出來的是, 由12/12/2016至31/10/2017
不知為何
Please HELP, THANKS Bro!!

SELECT [Employee Number], [Chinese Name], [English Name], [Tel Number], [Expiry Date] FROM Employee Where [Expiry Date] between #12/12/2016# and #11/1/2017#
  1.     Dim con As OleDbConnection
  2.     Dim da As OleDbDataAdapter
  3.     Dim dt As New DataTable
複製代碼
  1.         Dim today = DateTime.Now.Date
  2.         Dim an1 = today.AddDays(+31)
  3.         Dim an2 = today.AddDays(+61)
  4.         con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=|DataDirectory|\IWSDatabase.accdb")
  5.         con.Open()
  6.         da = New OleDbDataAdapter("SELECT [Employee Number], [Chinese Name], [English Name], [Tel Number], [Expiry Date] FROM Employee Where [Expiry Date] between #" + an1.Date + "# and #" + an2.Date + "#", con)
  7.         da.Fill(dt)
  8.         NotifyDataGridView.DataSource = dt.DefaultView
  9.         con.Close()
複製代碼

Expiry Date 個 datatype 系DATE 既話 , 甘an1.Date  最好加 : an1.Date.tostring("yyyy-MM-dd")
an2 都系

TOP

原因就係default用緊en-us format,即係MM/dd/yyyy...
咁你個query就變成2017年11月1日

TOP

Thank you so much!

It works now. ^.^

TOP

相關文章