How to use the .Net 4.0 Dynamic Keyword to convert a recordset to an object

This is a simple example of how to convert an old style ADODB recordset into a dynamic object using the .Net 4.0 dynamic keyword.

This example assumes that you have the ADODB referenced as an Interop.

            public static List<dynamic> AsDynaList(ADODB.Recordset recordset)
                List<dynamic> rs = new List<dynamic>();
                while (!recordset.EOF)
                    var fieldIndex = 0;
                    var test = new ExpandoObject() as IDictionary<string, object>;

                    foreach (ADODB.Field fld in recordset.Fields)
                        test.Add(fld.Name, recordset.Fields[fieldIndex].Value);
                return rs;


  1. Thanks for this snipet of code. It was exactly what I needed to integrate with a legacy application. Saved me lots of time.

    Thanks again.


  2. I’m impressed, I must say. Seldom do I encounter a blog that’s both educative and interesting,
    and without a doubt, you’ve hit the nail on the head.

    The problem is something that not enough folks aree speaking intelligently about.
    I am very happy that I stumbled across this in my search for something relating
    to this.

Comments are closed.