Basically, what I need to do is update a record in my datatable without knowing what the row index is. So I get the row index by searching the value in the columns of the datatable.
I have searched over the internet but I can’t understand why the code I have now only updates only the FIRST record in the datatable even when the value I’m searching for it is in the second row. What am I doing wrong?
private void SaveBtn__Click(object sender, EventArgs e)
{
if (SUpdateReq_Grd.SelectedRows.Count > 0)
{
if (MySkills_dataTable.Rows.Count > 0)
{
string SkillID = SkillID_Txt.Text;
string Proficiency = Proficiency_Cmb.SelectedItem.ToString();
string Yrs_Exp = YrsExperience_cmb.SelectedItem.ToString();
//find rowIndex of skill id
DataRow[] Rows = MySkills_dataTable.Select("SkillID='"+ SkillID + "'");
MySkills_dataTable.Rows[0]["Proficiency"] = Proficiency;
MySkills_dataTable.Rows[0]["Yrs_Experience"] = Yrs_Exp;
MySkills_dataTable.AcceptChanges();
}
}
}
I think you should use your
Rowsvariable to set the new values on, and not the complete datatable: