c# - How to use datetime picker to retrieve data from ms access database -


i creating 1 application in c# in using datetimepicker control. have created database in ms access contains 1 table date_entry, emp_no, emp_name, in_time, out_time columns.

now want retrieve these data in textbox clicking date on datetimepicker control. date point date in date_entry field of database , fetch data according date.

how it?

 private void datetimepicker1_valuechanged(object sender, eventargs e)  {  try  {  oledbconnection conn = new oledbconnection    ("provider=microsoft.jet.oledb.4.0,datasource=c:\\users\\jd\\desktop\\attendance.mdb");  oledbcommand cmd = new oledbcommand("select * attendance_details date_entry=" +     datetimepicker1.value + "", conn);  cmd.commandtype = commandtype.text;  oledbdataadapter da = new oledbdataadapter(cmd);  dataset ds = new dataset();  da.fill(ds, "attendance_details");  txtdate.text = ds.tables[0].rows[0][0].tostring();  txtempno.text = ds.tables[0].rows[0][1].tostring();  txtempname.text = ds.tables[0].rows[0][2].tostring();  txtintime.text = ds.tables[0].rows[0][3].tostring();  txtouttime.text = ds.tables[0].rows[0][4].tostring();  }  catch (exception ex)  {  messagebox.show(ex.tostring());  }  }  } 

there problems in above code. have refined it. work.

following should code:

private void datetimepicker1_valuechanged(object sender, eventargs e)  {  try  {   oledbconnection conn = new oledbconnection    ("provider=microsoft.jet.oledb.4.0,datasource=c:\\users\\jd\\desktop\\attendance.mdb");  con.open();  oledbcommand cmd = new oledbcommand("select * attendance_details date_entry=@dtpdate", conn);  cmd.parameters.addwithvalue("@dtpdate", datetimepicker1.value);  cmd.commandtype = commandtype.text;  oledbdataadapter da = new oledbdataadapter(cmd);  dataset ds = new dataset();  da.fill(ds);  txtdate.text = ds.tables[0].rows[0][0].tostring();  txtempno.text = ds.tables[0].rows[0][1].tostring();  txtempname.text = ds.tables[0].rows[0][2].tostring();  txtintime.text = ds.tables[0].rows[0][3].tostring();  txtouttime.text = ds.tables[0].rows[0][4].tostring();  con.close();  }  catch (exception ex)  {  messagebox.show(ex.message);  }   {    con.close();  }  }  } 

hope helpful.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -