I have a WPF app in which I have a DataGrid control that I am trying to bind to a DataTable as the result of a SQL Query. I'm not sure what I'm doing wrong. It seems pretty straight-forward but I guess not. See the screenshot and my code that produces that is below.
Code:
private void LoadEmployersToGrid()
{
DataTable dt = new DataTable();
Employer emp = new Employer();
cnn = DatabaseConnection();
if (cnn.State == ConnectionState.Open)
dt = emp.GetAllEmployerRecords(cnn);
Grid1.ItemsSource = dt.Rows;
}
Here is my SQL routine:
Code:
public DataTable GetAllEmployerRecords(SqlConnection cnn)
{
DataTable dt = new DataTable();
string sqlStr = "SELECT * FROM Employer";
SqlDataAdapter adp = new SqlDataAdapter(sqlStr, cnn);
adp.SelectCommand = new SqlCommand(sqlStr, cnn);
adp.Fill(dt);
return dt;
}
First, you've been here long enough to know that screen shots don't work here. The forum does funky stuff with it. Second, I'm getting up there in the years... I can't read that. Especially the important pat, which is the error. The fact that it is italicized (I think it is) isn't helping either. Even with my second set of eyes on, I can't really see that.
-tg
addendum..OK, when I get 4 inches from the screen, I can make it out... apparenty its a differnce between winforms and wpf.. it's looking for a list... I don't remember, and I can't try it, but see if the rows property has a .ToList() method on it...
Code:
Grid1.ItemsSource = dt.Rws.ToList();
If that still doesn't work, I've got nothing. Oddly, I'm having trouble finding the documentation pages for it. *shrug*