The following syntax converts a DataTable to a Dictionary .

 

in C#

Dictionary<string, string> dicCodes = ds.Tables[0].AsEnumerable()
                                    .ToDictionary<DataRow, string, string>(
                                        row => row.Field<string>("Column1Name"),
                                        row => row.Field<string>("Column2Name")
                                    );

 

in VB.NET

Dim dicCodes As Dictionary(Of String, String) =
    ds.Tables(0).AsEnumerable() _
    .ToDictionary(Of String, String)(
                                        Function(row) row.Field(Of String)("Column1Name"),
                                        Function(row) row.Field(Of String)("Column2Name")
                                    )

 

be the happy Gosu.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

+ Recent posts