I have migrated legacy code from vb to c#. The following migrated line of code raises an error:
using System.Data;
..
..
DataRow targetDataRow = targetDataTable.NewRow();
targetDataRow.SetField("DateValue", calendarRow.DateValue.ToShortDateString);
The error:
=Error CS1061 'DataRow' does not contain a definition for 'SetField' and no accessible extension method 'SetField' accepting a first argument of type 'DataRow' could be found (are you missing a using directive or an assembly reference?)
I know I can use it like:
targetDataRow["DateValue"] = calendarRow.DateValue.ToShortDateString);
But, is this the best practice to set the value to a field in DataRow object?
targetDataTableinto a typedDataTablewould be better. Then you may set field value like this:targetDataRow.DateValue = .... If you are migrating VB code it might be not a big extra work to accomplish this the same time.