Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate a Dictionary
Message
From
23/03/2011 11:55:11
 
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01504070
Message ID:
01504684
Views:
54
You are trying to put too much into just a list. Your list can only have a single string value for each entry. You will need either a list of key value pairs, or a dictionary. Try one of the following:
DataTable dt = ds.Tables[0];
List< KeyValuePair<string, string>> MyList = dt.Columns.OfType<DataColumn>().Select(dc => new KeyValuePair<string, string>(dc.ColumnName, dt.Rows[0][dc].ToString())).ToList();
or
DataTable dt = ds.Tables[0];
Dictionary<string, string> MyDictionary = dt.Columns.OfType<DataColumn>().ToDictionary(dc => dc.ColumnName, dc => dt.Rows[0][dc].ToString());
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform