Converting a dynamic list into an ADODB Recordset

This follows on from another article i wrote a while ago [How to use the .Net 4.0 Dynamic Keyword to convert a recordset to an object] This code shows how to convert from the dynamic list back into a recordset.

The example does not attempt to determine the field type so it just sets it to an VarChar(255) field which is nullable. If you want to add your own code in here to determine the type and size etc… please feel free.

      public ADODB.Recordset ConvertToRecordSet(List obj){
            ADODB.Recordset _rs = new ADODB.Recordset() {  CursorType= ADODB.CursorTypeEnum.adOpenDynamic, CursorLocation = ADODB.CursorLocationEnum.adUseClient };

            foreach (KeyValuePair item in obj as IDictionary) {
                _rs.Fields.Append(item.Key,
                                    ADODB.DataTypeEnum.adVarChar,
                                    255,
                                    ADODB.FieldAttributeEnum.adFldIsNullable,
                                    item.Value);
            }
            _rs.Open((object)null, (object)null, ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockBatchOptimistic, 0);
            return _rs;
        }

9 Comments

  1. Hi there I stumbled upon your page by mistake when i was searching Msn for this concern, I must tell you your blog is absolutely very helpful I also like the theme, its great!

  2. Each add on to car insurance has its own importance but this does nnot mean you need to take all of them.

    Ask your auto insurance agent to provide more information to you regarding these
    discounts in order to save more money. Be careful about the
    insurance cover you opt for with the hire car.

    Here is my website; ami car insurance quote nz

  3. Hi there! I know this is kind of off topic but I was
    wondering which blog platform are you using for this site?

    I’m getting tired of WordPress because I’ve had problems
    with hackers and I’m looking at alternatives for another
    platform. I would be great if you could point me in the direction off a good platform.

  4. Magnificent items from you, man. I have be mindful your stuff previous to and you’re
    just extremely magnificent. I actually like what you’ve obtained right here, certainly like what you are stating and the best way in which you are saying it.

    You’re making it enjoyable and you continue to care for to stay it wise.
    I can’t wait to read much more from you. This is really a terrific site.

    Review my website … web page (Christi)

  5. Hey there are using WordPress for your site platform?

    I’m new to the blog world but I’m trying to get started and create my own. Do you need
    any html coding knowledge to make your own blog? Any help would be really appreciated!

    My homepage: Hamish

  6. Having read this I thought it was really informative. I appreciate you
    spending some time and effort to put this informative article together.

    I once again find myself spending a lot of time both reading and commenting.
    But so what, it was still worthwhile!

    my homepage; google.de (Rufus)

Comments are closed.