我正在尝试使用Access中的信息填充我的列表框,我做得对吗?或者我错过了一些东西。因为当我搜索我的列表框时没有被填充。我正在使用DateTimePicker作为搜索,以查找特定日期以及与其相关的所有信息。
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "SELECT *FROM Booking WHERE Date=" + dateTimePicker1.Text + "";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader["CID"].ToString());
listBox1.Items.Add(reader["VehicleNumber"].ToString());
listBox1.Items.Add(reader["Date"].ToString());
listBox1.Items.Add(reader["Time"].ToString());
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
答案 0 :(得分:0)
您需要一个适当的日期值字符串表达式格式:
string query = "SELECT * FROM Booking WHERE [Date] = #" + dateTimePicker1.Value.ToString("yyyy'/'MM'/'dd") + "#";