Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to enumerate DataColumns in a DataTable
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00722302
Message ID:
00722311
Views:
28
This message has been marked as the solution to the initial question of the thread.
You just need to tweak your code just a little bit. You need to iterate through the Columns collection inside the DataTable. Try this:
DataTable DT = MyDataSet.Tables[0];
foreach(DataColumn DC in DT.Columns)
{
  ColumnName[Col] = DC.ColumnName;
  MaxLength[Col] =  DC.MaxLength;
  Nullable[Col] = DC.AllowDBNull;
}
>All,
>
>I was looking to parse through all of the Columns of a DataTable to see if the Column accepted nulls:
>
>DataTable DT = MyDataSet.Tables[0];
>foreach(DataColumn DC in DT)
>{
>  ColumnName[Col] = DC.ColumnName;
>  MaxLength[Col] =  DC.MaxLength;
>  Nullable[Col] = DC.AllowDBNull;
>}
>
>But I get an
>
>foreach statement cannot operate on variables of type 'System.Data.DataTable' because System.Data.DataTable' does not contain a definition for 'GetEnumerator', or it is inaccessible
>
>Any workaround? How do I implement GetEnumerator on a DataTable?
>
>TIA,
>Doug
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform