Try inserting this line:
row["Marks"] = marks[i];
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi. I have 2 string arrays, which are of similar length. Example: if Array1 has values - John, Ron, Max , Array2 has values - 20, 45, 10 I have a data table which has the column - Name, Marks. Name has values of John, Ron and Max. I want to compare the datatable column Name with the Array1 , and if matches, then I want to set the Marks column corresponding to it. If John is matched, then marks should be 20 , Ron is matched then marks to be set as 45.. I have tried the first loop of comparing, but not sure, how to set the second loop for Array2. How to fix this ?
// DataTable is dataResult
string[] names = new string[] { }; // contains names
string[] marks = new string[] { }; // contains marks
foreach (DataRow row in dataResult.Rows)
{
for (int i = 0; i < names.Length; i++)
{
if (names[i].Equals(row["USER_NAME"]))
{
// to match the mark
}
}
}
Try inserting this line:
row["Marks"] = marks[i];