Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
XamDataGrid Updating Active Record
posted

I have a loop going through the records in a XamDataGrid and updating the database using a SqlDataAdapter. The problem is that its only updating the first record. I read that the Records object only contains the root collection of records. How can i update the selected active record?

                daSelectUsers = new SqlDataAdapter("SELECT Name, Age, conn);
                DataSet DS = new DataSet("DataSet");
                conn.Open();
                foreach (DataRecord record in recipeSegmentsXamDataGrid.Records)
                    {
                        daUsersCommand = new SqlCommand("UPDATE Users SET Name = '" + record.Cells["Name"].Value + "'," +
                                                                                        "Age = '" + record.Cells["Age"].Value + "'," +
                                                                                        "WHERE ID = '" + ID + "' ", conn);

                        daSelectUsers.UpdateCommand = daUsersCommand;
                        SqlDataAdapter sda = new SqlDataAdapter(daUsersCommand);
                        daSelectUsers.Fill(DS, "Users");
                        sda.Update(DS, "Users");
                        daUsersCommand.ExecuteNonQuery();

                        conn.Close();
                    }