Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate a Dictionary
Message
 
À
23/03/2011 11:55:11
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01504070
Message ID:
01504779
Vues:
43
>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());
>
Sorry Rob - I meant Dictionary - bit of thread drift creeping in - I've been working with lists and dictionaries in the same thread - my bad - your second suggestion looks perfect - where did you learn all this stuff ?
Regards,
Peter J. Kane



Pete
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform