当我对MDB
数据库执行下面的代码时,数据表为空,但是当我在针对数据库的查询工具中运行它时,它返回2条记录。
可能是什么问题?
参数的日期格式是否存在问题(即8/5/13 vs 5/8/13)?
Using oDB As OleDbConnection = GetDbConnection()
Using oCmd As New OleDbCommand("SELECT * " & _
" FROM Table1, Table2" & _
" WHERE (Table1.Date BETWEEN @Date1 AND @Date2) AND (Table1.Id IS NULL) AND (Table2.number = Table1.num) AND (Table1.code1 = Table2.code1) ", oDB)
oCmd.Parameters.AddWithValue("@Date1", Date.Today)
oCmd.Parameters.AddWithValue("@Date2", Date.Today.AddDays(Me.intDaysAhead))
oDB.Open()
dt = New DataTable()
Using da As OleDbDataAdapter = New OleDbDataAdapter(oCmd)
da.Fill(dt)
End Using
End Using
End Using
答案 0 :(得分:1)
我认为你是对的。我建议指定参数类型OleDbType
oCmd.Parameters.Add("@Date1", OleDb.OleDbType.Date).Value = Date.Today