How to convert a column of DataTable to a List
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Converting one DataTable column into a List is a common cleanup step when older ADO.NET code needs to feed newer application logic or APIs that expect generic collections. The most reliable approach is to project rows with LINQ, use the correct typed accessor, and decide up front how null values and conversion failures should be handled.
Build the DataTable
A DataTable stores values as object, so your first task is deciding what type the list should hold. If the column is conceptually strings, project strings. If it is integers, read integers directly instead of converting everything through text.
Use LINQ with AsEnumerable
The standard pattern is AsEnumerable, followed by Select, followed by ToList. This is concise and easy to read.
Field<T> is preferable to direct index access because it gives you typed results and integrates cleanly with DBNull handling.
Convert Numeric Columns to Typed Lists
If the source column already has a numeric type, read it as that type.
This avoids unnecessary boxing and parsing. It also makes errors more obvious if the data does not match the schema you think you have.
Handle Nulls Deliberately
Database data often contains nulls. For nullable columns, project to nullable types or substitute a default value.
If you need to preserve the distinction between missing and present values, use List<string?> or List<int?> where appropriate.
Filter While Converting
Often the list should contain only a subset of the rows. Add filtering before ToList.
This keeps the transformation in one readable pipeline instead of splitting it across several loops.
A Loop-Based Option
LINQ is usually the clearest solution, but an explicit loop is fine if you need custom branching or more detailed error handling.
Use this style when the projection is more complex than a simple column read.
Common Pitfalls
A common mistake is using row["Name"].ToString() for everything. That hides null handling, can turn DBNull into an empty-looking string, and makes typed failures harder to detect. Another problem is forgetting to reference System.Data.DataSetExtensions, which provides AsEnumerable in older project setups.
Be careful when the column type in the DataTable does not match the type you request in Field<T>. If the table stores strings and you ask for int, you will get runtime errors. In that case either fix the schema or project with parsing logic instead of assuming a typed column exists.
Summary
- use
AsEnumerable,Select, andToListfor the standard conversion pattern - prefer
Field<T>over raw index access for typed reads - project numeric columns to numeric lists instead of converting through strings
- decide explicitly how nulls should be handled
- switch to an explicit loop when conversion rules become more complex than a simple projection
Related reading
- How to convert a dataframe to a dictionary
- How to convert a Java 8 Stream to an Array?
- How to convert a JSON string to a dictionary?
- How to convert a ListString into a comma separated string without iterating List explicitly
- How to convert a list of generic tasks of different types that are stored in a ListTask, to a TaskListobject?
- How to convert DateTime? to DateTime
- How to convert a nested Python dict to object?
- How to convert an array into an object?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.