Use Enum to Access DataColumns in a DataRow for Performance. Integer indexes are faster than String indexes for accessing an Item in a DataRow.
I am in the midst of refactoring some code written in the early days of VB.NET, when I and other project members were just learning .NET strategies. The particular method is walking through the rows of a DataTable. In the first place, it had many lines of code like the following line.
| jlength = dt.Rows(i).Item("job_length") |
| Dim dr As DataRow For i = 0 To inbrRows dr = dt.Rows(i) |
| jlength = dr("job_length") |
| jlength = dr(12) |
| Private Enum MDF End Enum |
| Private Enum MDF Select author_id, date_dictated, transcribed_file_time, work_type,excel_job_number,foreign_batch, job_number, author_name, excel_author_name, department, date_transcribed,dictation_date_time,transcription_date_time,job_length End Enum |
| Private Enum MDF author_id date_dictated transcribed_file_time work_type foreign_batch job_number author_name department date_transcribed dictation_date_time transcription_date_time job_length End Enum |
| sLastDept = CStr(dr(MDF.department)) sLastWT = CStr(dr(MDF.work_type)) |