Shop OBEX P1 Docs P2 Docs Learn Events
display records from ms access to datagridview with dateTimePicker — Parallax Forums

display records from ms access to datagridview with dateTimePicker

KsaryKsary Posts: 2
edited 2013-10-28 16:09 in General Discussion
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 don’t 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

  • davejamesdavejames Posts: 4,047
    edited 2013-10-28 13:41
    Hello Ksary - welcome to the Forum.

    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
  • Mike GMike G Posts: 2,702
    edited 2013-10-28 14:47
    Ksary, you select filters by an exact DateTime. I'm guessing you want WHERE SignIn >= dateTimePicker1.Value.ToShortDateString()
    SELECT Username FROM SignInTime WHERE SignIn >= @SignIn
    

    The correct syntax depends on the defined column type which is not in your post.
  • KsaryKsary Posts: 2
    edited 2013-10-28 16:09
    Mike G wrote: »
    Ksary, you select filters by an exact DateTime. I'm guessing you want WHERE SignIn >= dateTimePicker1.Value.ToShortDateString()
    SELECT Username FROM SignInTime WHERE SignIn >= @SignIn
    

    The correct syntax depends on the defined column type which is not in your post.

    Thank You so much....Its now working.
Sign In or Register to comment.