Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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];
                }
            }
Posted
Comments
Bajirao_ 29-Oct-13 8:46am    
On primary observation i can suggest :
Go to Access DB and in tab Create->Query wizard.
Create new query and test that first with values. check for expected result.
Ones done then go for the datetimepicker value and compair expected format of value from dtpicker and actual value.

Check your template of grid in case if it exists, for its columns.


hope it helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900