Quote:
If I do as such. Will the DataTable dt be updated with these values?
Yes, only the filtered rows in the
dt
will get updated to new value.
Quote:
Since I am working to create a Windows Service, debugging would be a pain. Hence, asking here.
You could have created a simple console application and tried.
refer the below
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace CPTemp
{
class Program
{
static void Main(string[] args)
{
DataTable dt = new DataTable();
dt.Columns.Add("Col1");
dt.Rows.Add("ABC123");
dt.Rows.Add("ABC123");
dt.Rows.Add("test");
dt.Rows.Add("test123");
MyMethod(dt);
string row1 = dt.Rows[0][0].ToString();
string row2 = dt.Rows[1][0].ToString();
string row3 = dt.Rows[2][0].ToString();
string row4 = dt.Rows[3][0].ToString();
}
private static void MyMethod(DataTable dt)
{
List<DataRow> rows = dt.Select("Col1='ABC123'").ToList();
foreach (DataRow row in rows)
{
row["Col1"] = "DEF456";
}
}
}
}