WPF DataGrid没有显示我的数据

时间:2015-03-06 17:18:47

标签: c# .net wpf ms-access wpfdatagrid

这是我尝试绑定到DataGrid的方法,它是空白的

private void getDataFromAccess()
{
    using (OleDbConnection sqlConn = new OleDbConnection())
    {
        sqlConn.ConnectionString = connectionString;
        string queryString = "SELECT SignIn.VisitorFirstName, SignIn.VisitorLastName, SignIn.SignInDateTime FROM UserList INNER JOIN SignIn ON UserList.POid = SignIn.AssignedPO WHERE (((UserList.FirstName)='First') AND ((UserList.LastName)='Last')) AND SignIn.Complete=False ORDER BY SignIn.SignInDateTime DESC";
        sqlConn.Open();

        DataTable table = new DataTable();
        OleDbDataAdapter a = new OleDbDataAdapter(queryString, sqlConn);

        a.Fill(table);                
    }
}

这是我的控制台代码,用于查看我是否能够访问数据。它将数据吐出到colsole

private void testDB()
{
    string connectionString =
        @"Provider=Microsoft.ACE.OLEDB.12.0;" +
        @"Data Source=R:\\Data\backend.accdb;" +
        @"User Id=;Password=;";

    string queryString = "SELECT SignIn.VisitorFirstName, SignIn.VisitorLastName, SignIn.SignInDateTime FROM UserList INNER JOIN SignIn ON UserList.POid = SignIn.AssignedPO WHERE (((UserList.FirstName)='Sophia') AND ((UserList.LastName)='Peele')) AND SignIn.Complete=False ORDER BY SignIn.SignInDateTime DESC";

    using (OleDbConnection connection = new OleDbConnection(connectionString))
    using (OleDbCommand command = new OleDbCommand(queryString, connection))
    {
        try
        {
            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader[0].ToString() + " " + reader[1].ToString());
            }

            reader.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

我有这些私人"全球到班级"变量

private String currentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\')[1];
private String firstName, lastName;
private int lastMinute = 1;
private String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source=R:\\KIOSK\\ProbationSignIn_be.accdb;" + @"User Id=;Password=;";
private DataTable table;
private OleDbDataAdapter dataAdapter;

我正在使用WPF和Access2013以及DataGrid。如果有更好的方法,请告诉我

该项目的目标是

  1. 监控来自访问某个人的新访问者的表格
  2. 一旦此人完成后更新记录"看到"访客。

0 个答案:

没有答案