Saturday 16 January 2016

Fill dictionary from reader object in c#


Hello guys.

This is the simple code to fill dictionary from reader object.


Dictionary<String, String> AdminSettings = new Dictionary<String, String>();


Now your database code goes here.


while (reader.Read())

                {

                    AdminSettings = Enumerable.Range(0, reader.FieldCount)

                     .ToDictionary(

                         s => reader.GetName(s),

                         s => Convert.ToString(reader.GetValue(s)));

                }


Thanks…

No comments:

Post a Comment