Steps to modify data in a DataTable
Suppose we have a DataTable with columns Name,Age, Status
//DataTable dtRecords;
DataRow[] rows = dtRecords.Select();
if (rows != null && rows.Length > 0)
{
foreach (DataRow row in rows)
{
if (Convert.ToInt16(row["Age"]) > 18 )
{
row["Status"] = "Can Vote";
}
}
}
OR
you can also select specific rows then work accordingly
string name = "xxx";
DataRow[] rows = dtRecords.Select("Name = " + name);
if (rows != null && rows.Length > 0)
{
foreach (DataRow row in rows)
{
lblName.Text = Convert.ToString(row["Name"]);
}
}
0 Comment(s)