display records from ms access to datagridview with dateTimePicker
Ksary
Posts: 2
I am trying to display the username that had signed in on the selected date in a dateTimePicker,from ms access database to c# datagridview.
I dont know where I am wrong, it only displays the column name but not the records.
string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/ EmployeeAttendanceRegister.accdb";
using (var cn = new OleDbConnection(strConn))
{
cn.Open();
using (var cmd = new OleDbCommand("SELECT Username FROM SignInTime WHERE SignIn =@SignIn", cn))
{
cmd.Parameters.Add(new OleDbParameter("@SignIn",dateTimePicker1.Value.ToShortDateString()));
using (OleDbDataAdapter oda = new OleDbDataAdapter(cmd))
oda.Fill(dt);
dataGridView1.DataSource = dt.Tables[0];
}
}
I dont know where I am wrong, it only displays the column name but not the records.
string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/ EmployeeAttendanceRegister.accdb";
using (var cn = new OleDbConnection(strConn))
{
cn.Open();
using (var cmd = new OleDbCommand("SELECT Username FROM SignInTime WHERE SignIn =@SignIn", cn))
{
cmd.Parameters.Add(new OleDbParameter("@SignIn",dateTimePicker1.Value.ToShortDateString()));
using (OleDbDataAdapter oda = new OleDbDataAdapter(cmd))
oda.Fill(dt);
dataGridView1.DataSource = dt.Tables[0];
}
}
Comments
FYI, the blog post of this same subject falls under the "duplication of posts" noted in the Forum Guidelines and has been removed.
http://forums.parallax.com/showthread.php/134682-Forum-Guidelines
The correct syntax depends on the defined column type which is not in your post.
Thank You so much....Its now working.