1

Lets say you have a datatable with the following three columns:

ID,Size,Value

Is it possible to update the value column of a specific row based on the value of the ID of that row, pretty much to be able to run a SQL query of there is faster or better way?

1 Answer 1

1

Is it possible to update the value column of a specific row based on the value of the ID of that row

Yes, you can use DataRow.SetField and a little bit of Linq:

var rowsToUdate = dt.AsEnumerable()
    .Where(r => r.Field<int>("ID") == id);
foreach(DataRow row in rowsToUpDate)
    row.SetField("Value", newValue);

...pretty much to be able to run a SQL query of there is faster or better way?

So do you want to update the database instead of the DataTable? This part is confusing.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to be able to do the code you provided above, but select * on column ID and not need a where clause?
@user2593590: What do you mean with "select * on column ID and not need a where "?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.