What should be more appropriate to use when you want to initialize class properties from datatable.
i.e.
name=dt.Rows[0][0] or name=dt.Rows[0]["Name"]
Which approach is more scalable any easy to handle.
Currently I uses 2nd approach but feels like if I use indexes rather than name that i only need to change stored procedures rather that UI also.
But compromises readability of code. So What should I go for
One option is to have something in between:
That gives you one place to change if the column ordering/definitions change, but also gives readable code at the point of access. I’m not sure it addresses the issue of having to change both the UI code and the stored procedures at the same time: if your SPs are effectively changing their public interface, you should expect to change the UI code. However, this approach can reduce the pain of that change, as well as not littering your code with magic values.
(You might also want to consider strongly typed datasets… or moving to a non-
DataTabledata solution such as the Entity Framework. It may not be appropriate in your situation, but it’s worth considering.)