I am trying to select rows from a datatable and update a particular value in the selected rows.
Since it is updation therefore we cannot use an assign.
Hence, I used an ‘Invoke Code’.
Please find the snaps of the code inside Invoke Code.
Though the vb.net code doesn’t show any error, while running the same I get the error as
“Exception has been thrown by the target of an invocation”.
I guess there is a problem with the action done in the ForEach method in your expression.
The following code is in C# and it is working. Please check -
dt1.Select("User = 'Arnold'").ToList().ForEach(delegate (DataRow name)
{
name.SetField<string>(1,"Apple");
Console.WriteLine(name.Field<String>("Client"));
});
dt1 is data table contains 3 columns - User, Client, Date
I am filtering the table based on User and Updating the Second Column value using SetField.
You code seems synthatically correct so I imagine the issue is elsewhere.
Are you sure that the first part (.Select) returns any row? that the column names are correct and the State datatype is a string, that Pan card number is a string as well?
A trick you can use, to get the proper exception message from the invoke code is to refer to its “inner exception”.
See example bellow
Cheers
@KarthikByggari Is there a way where I can update the column value in one go, without using a for each?
Moreover, if this updation can be reflected in the main datatble for those filtered rows it would be really time saving!
@PRIYA_GUPTA
The values will reflect in the main data table.
This C# code is erring at “delegate” while I use it in ‘Invoke Code’.
Can you please help?
Hi Priya,
Were you able to resolve this?
Even I am stuck using vb code
Did you resolve this one? if not share ur xaml