i am having a Datagrid that loads data from database and each time each row is selected all row shows up in one textbox. with the exception of the id column and name column like this;
https://docs.microsoft.com/answers/storage/attachments/77315-wpf.png
i would like to update each row as selected with the changed values other than with its original values from that one textbox to their respective rows; for instance;
Row Dennis Math original value is 67 but will be update with the changed value 1st likewise other Rows.
What I have tried:
(am using c# in wpf)(the original values will be clear like this; so it won't be a problem) i just want to update each row as selected with the changed values; 1st, 2nd etc;
txtresults.Clear();
txtresults.Text += Environment.NewLine;
txtresults.Text += string.Join(" ", parts);
here is my selection changed event of datagrid
<pre>DataGrid dg = sender as DataGrid;
DataRowView dr = dg.SelectedItem as DataRowView;
if (dr != null)
{
if (dgvGrade.SelectedItems.Count > 0)
{
foreach (var obj in dgvGrade.SelectedItems)
{
str += dr["MATH"] +"\n ";
}
}
else
{
}
textbox1.Text = str;
this is what i have tried with the update button;
private void btnupdategraderecord_Click(object sender, RoutedEventArgs e)
{
SqlConnection Conn = new SqlConnection(shoolmanangmentconn);
Conn.Open();
SqlCommand cmd = new SqlCommand("UPDATE tbl_TestingTheApplicationSubject SET MATH=@MATH WHERE IDNO=@IDNO", Conn);
cmd.CommandType = CommandType.Text;
string[] arryval = txtresults.Text.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
int i = 0;
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@IDNO", txtids.Text);
cmd.Parameters.AddWithValue("@MATH", arryval[i++]);
cmd.ExecuteNonQuery();
}