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();
                    }

Parents
  • 18204
    Verified Answer
    Offline posted

    Hello,

    Thank you for posting in our forums!

    With the code you provided, it looks like you are looping through each DataRecord, but you close the connection after the first one and never open it again.

    Does this work if you keep the connection open?

    Looking forward to hearing from you.

Reply Children
No Data