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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -