I am creating one application in C# in which I am using datetimepicker control. I have created a database in MS Access which contains one table with Date_Entry, Emp_No, Emp_Name, In_Time, Out_Time
columns.
Now I want to retrieve these data in textbox by clicking date on datetimepicker control. This date is point the date in Date_Entry
field of database and fetch the data according to that date.
How to do 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 * FROM Attendance_Details WHERE 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());
}
}
}