Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate a Dictionary
Message
De
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:
01504684
Vues:
53
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());
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform