代码示例:
'使用查询字符串时的示例 Dim filter as String = "SELECT * FROM Table1 WHERE DateField = #" & DateTimePicker1.Value.ToString("MM/dd/yyyy") & "#" Dim adapter As New OleDbDataAdapter(filter, conn) Dim ds As New DataSet() adapter.Fill(ds, "Table1") DataGridView1.DataSource = ds.Tables("Table1")
'使用参数化查询时的示例 Dim cmd As New OleDbCommand("SELECT * FROM Table1 WHERE DateField = @date", conn) cmd.Parameters.AddWithValue("@date", DateTimePicker1.Value) Dim adapter As New OleDbDataAdapter(cmd) Dim ds As New DataSet() adapter.Fill(ds, "Table1") DataGridView1.DataSource = ds.Tables("Table1")
'使用LINQ时的示例 Dim query = From row In Table1.AsEnumerable() Where row.Field(Of DateTime)("DateField") = DateTimePicker1.Value Select row DataGridView1.DataSource = query.ToList()