0

Here's a sample code. i want to know how you can use this code for wpf datagrid.

whenever I try this code it gets an error in the dataStudents.Rows.Add Line

public void LoadStudents()
            {
                dataStudents.Rows.Clear();
                dataAssStud.Rows.Clear();

                con.Open();
                cmd = new SqlCommand(@"SELECT StudID, Lname, 
                    Fname, MI FROM Students;", con);
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    dataStudents.Rows.Add(rdr[0].ToString(), rdr[1].ToString(),
                           rdr[2].ToString(), rdr[3].ToString());
                    dataAssStud.Rows.Add(rdr[0].ToString(), rdr[1].ToString(),
                           rdr[2].ToString(), rdr[3].ToString());
                }

                con.Close();
            }
5
  • What is the error exactly? And what is dataStudents? Commented Jan 27, 2015 at 8:40
  • it says 'System.Windows.Controls.DataGrid' does not contain a definition for 'Rows" and no extension method 'Rows' accepting a first argument of type 'System.Windows.Controls.DataGrid' could be found( are you missing a using directive or an assembly reference?) Commented Jan 27, 2015 at 8:46
  • dataStudents is the name of the DataGrid Commented Jan 27, 2015 at 8:48
  • I'm not familiar with WPF concept but looks like you can't add a new row to datagrid like this. Read: stackoverflow.com/questions/24095172/… Commented Jan 27, 2015 at 8:49
  • I'm checking it now. Thanks. Commented Jan 27, 2015 at 8:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.