c# - Populate Listbox using DateTimePicker -
i'm trying populate listbox information access, doing right? or missing few things. because when search listbox isn't being populated. i'm using datetimepicker search specific dates , information relating displayed.
try { connection.open(); oledbcommand command = new oledbcommand(); command.connection = connection; string query = "select *from booking 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); }
you need proper format string expression of date value:
string query = "select * booking [date] = #" + datetimepicker1.value.tostring("yyyy'/'mm'/'dd") + "#";
Comments
Post a Comment