0

When I execute the code below against an MDB database, the data table is empty, however when I run this in a query tool against the database it returns 2 records.

What could be the problem?

Is it an issue with the date format of the parameters (ie. 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
4

1 回答 1

1

我想你是对的。我建议指定一个参数类型OleDbType

 oCmd.Parameters.Add("@Date1", OleDb.OleDbType.Date).Value = Date.Today
于 2013-05-08T16:32:19.303 回答