Data in DataTables
-
Hi all, I have a DataTable object and the 4th column has DateTime objects stored in it. To get at the DateTimes i am doing the following.
DateTime dt; for (int x = 0; x < Table.Rows.Count; x++) { dt = (DateTime)Table.Rows[x].ItemArray[3] ..... Some other code here ..... }
Is there any way of getting at the DateTime object in the column without casting? This is my biggest overhead by far in the method which is fine for a few hundred iterations but sometimes i am going through tens of thousands of iterations and it's a tad slow. Anyone able to help?? Cheers Kev -
Hi all, I have a DataTable object and the 4th column has DateTime objects stored in it. To get at the DateTimes i am doing the following.
DateTime dt; for (int x = 0; x < Table.Rows.Count; x++) { dt = (DateTime)Table.Rows[x].ItemArray[3] ..... Some other code here ..... }
Is there any way of getting at the DateTime object in the column without casting? This is my biggest overhead by far in the method which is fine for a few hundred iterations but sometimes i am going through tens of thousands of iterations and it's a tad slow. Anyone able to help?? Cheers KevWhen using the DataTable you will have to do the casting. One solution would be to take another data structure. You should also try not taking the ItemArray property as I think it produces a bit overhead (Im not 100% in this):
DateTime dt;
for (int x = 0; x < Table.Rows.Count; x++)
{
dt = (DateTime)Table.Rows[x][3]
.....
Some other code here
.....
}