Creating ADODB recordset in code

Discussion in 'Microsoft C# .NET' started by Raymon, Aug 7, 2012.

  1. Raymon

    Raymon Guest

    I am trying to create an ADODB recordset but I am getting an error.
    (Don't say to use ADO.Net. I have to use classic ADO; it is a legacy
    requirement.)

    In old VB6 I used to create a disconnected ADODB recordset like:

    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.Fields.Append "Col1", adVarChar, 30
    rs.Open

    In C# I try:

    ADODB.Recordset rs = new ADODB.Recordset();
    rs.Fields.Append("Col1", adVarChar, 30);

    But the last statement gives a MissingMethod exception, as if
    there is no Append method. Although it shows up in the
    Intellisense.
    This is not caught during compile, only at runtime.

    Is there a way to create an ADODB recordset in code in .Net?

    BTW, I am using .Net Framework 4.0.
     
    Raymon, Aug 7, 2012
    #1
    1. Advertisements

  2. Raymon

    bradbury9 Guest

    El martes, 7 de agosto de 2012 09:20:16 UTC+2, Raymon escribió:
    > I am trying to create an ADODB recordset but I am getting an error.
    >
    > (Don't say to use ADO.Net. I have to use classic ADO; it is a legacy
    >
    > requirement.)
    >
    >
    >
    > In old VB6 I used to create a disconnected ADODB recordset like:
    >
    >
    >
    > Dim rs As ADODB.Recordset
    >
    > Set rs = New ADODB.Recordset
    >
    > rs.Fields.Append "Col1", adVarChar, 30
    >
    > rs.Open
    >
    >
    >
    > In C# I try:
    >
    >
    >
    > ADODB.Recordset rs = new ADODB.Recordset();
    >
    > rs.Fields.Append("Col1", adVarChar, 30);
    >
    >
    >
    > But the last statement gives a MissingMethod exception, as if
    >
    > there is no Append method. Although it shows up in the
    >
    > Intellisense.
    >
    > This is not caught during compile, only at runtime.
    >
    >
    >
    > Is there a way to create an ADODB recordset in code in .Net?
    >
    >
    >
    > BTW, I am using .Net Framework 4.0.


    Check this link, seems to be what you are looking for http://support.microsoft.com/kb/308611/en-us

    BTW, it's is first google result for "adodb recordset c#"
     
    bradbury9, Aug 7, 2012
    #2
    1. Advertisements

  3. Raymon

    Jeff Johnson Guest

    "bradbury9" <> wrote in message
    news:...

    >> I am trying to create an ADODB recordset but I am getting an error.


    > Check this link, seems to be what you are looking for
    > http://support.microsoft.com/kb/308611/en-us


    I didn't see anything in that link that talked about creating a recordset
    from scratch, which is what the OP is asking about.
     
    Jeff Johnson, Aug 7, 2012
    #3
  4. Raymon

    Jeff Johnson Guest

    "Raymon" <> wrote in message
    news:...

    > (Don't say to use ADO.Net. I have to use classic ADO; it is a legacy
    > requirement.)


    May I ask what this legacy requirement is? Are you going to pass the
    Recordset to a COM object?
     
    Jeff Johnson, Aug 7, 2012
    #4
  5. Raymon

    bradbury9 Guest

    El martes, 7 de agosto de 2012 18:54:55 UTC+2, Jeff Johnson escribió:
    > "bradbury9" <> wrote in message
    >
    > news:...
    >
    >
    >
    > >> I am trying to create an ADODB recordset but I am getting an error.

    >
    >
    >
    > > Check this link, seems to be what you are looking for

    >
    > > http://support.microsoft.com/kb/308611/en-us

    >
    >
    >
    > I didn't see anything in that link that talked about creating a recordset
    >
    > from scratch, which is what the OP is asking about.



    You are right, Yaymon's error seems to be related with the reference

    Dim rsInputBuffer As New ADODB.Recordset
    rsInputBuffer.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    rsInputBuffer.Fields.Append("Comment", ADODB.DataTypeEnum.adBoolean)
    rsInputBuffer.Fields.Append("LineData", ADODB.DataTypeEnum.adChar, 100)
    rsInputBuffer.Open()

    This code works fine, but must be carefull with the reference:

    "Seems that I have solved the problem adding a reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library"

    http://social.msdn.microsoft.com/Fo...b/thread/f84cdc9c-f684-46d6-9b6f-757d047b00d5
     
    bradbury9, Aug 7, 2012
    #5
  6. Raymon

    Raymon Guest

    On Tue, 7 Aug 2012 12:55:29 -0400, "Jeff Johnson" <>
    wrote:

    >"Raymon" <> wrote in message
    >news:...
    >
    >> (Don't say to use ADO.Net. I have to use classic ADO; it is a legacy
    >> requirement.)

    >
    >May I ask what this legacy requirement is? Are you going to pass the
    >Recordset to a COM object?
    >


    Yes.
    An application is being converted from VB6/ADODB to C#/ADO.Net, piece
    by piece.
    Until the whole thing is converted to .Net we have to live in this
    hybrid environment, converting from ADODB to ADO.Net and
    vice versa.
    I had no problem converting ADODB recordset to ADO.Net DataTable.
    But ran into the the problem going the other way around.

    Anyway, doing some more research I found out the problem.
    It seems that ADODB is broken in .Net framework 4.0 which is
    our target framework.
    If I change the target framework to 3.5 or lower, the code I gave
    works without problem.
     
    Raymon, Aug 8, 2012
    #6
  7. Raymon

    bradbury9 Guest

    El miércoles, 8 de agosto de 2012 04:57:14 UTC+2, Raymon escribió:
    > Anyway, doing some more research I found out the problem.
    >
    > It seems that ADODB is broken in .Net framework 4.0 which is
    >
    > our target framework.
    >
    > If I change the target framework to 3.5 or lower, the code I gave
    >
    > works without problem.


    Which is one of the solutions that my last link says. From my previous link:

    "So it sounds like there are two answers here:
    - When using Visual Studio 2010 , you can change the Target .NET Framework of your project from ".NET Framework 4.0" to ".NET Framework 3.5" or ".NET Framework 3.5 Client Profile"
    - Or you can do as tix61 suggests and change your reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library""

    Have you tried changing the reference? It may work in Framework 4.0
     
    bradbury9, Aug 8, 2012
    #7
  8. Raymon

    Raymon Guest

    On Wed, 8 Aug 2012 01:49:57 -0700 (PDT), bradbury9
    <> wrote:

    >El miércoles, 8 de agosto de 2012 04:57:14 UTC+2, Raymon escribió:
    >> Anyway, doing some more research I found out the problem.
    >>
    >> It seems that ADODB is broken in .Net framework 4.0 which is
    >>
    >> our target framework.
    >>
    >> If I change the target framework to 3.5 or lower, the code I gave
    >>
    >> works without problem.

    >
    >Which is one of the solutions that my last link says. From my previous link:
    >
    >"So it sounds like there are two answers here:
    >- When using Visual Studio 2010 , you can change the Target .NET Framework of your project from ".NET Framework 4.0" to ".NET Framework 3.5" or ".NET Framework 3.5 Client Profile"
    >- Or you can do as tix61 suggests and change your reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library""
    >
    >Have you tried changing the reference? It may work in Framework 4.0


    "Microsoft ActiveX Data Objects Recordset 2.8 Library" is reference to
    ADOR object model.
    That's not the same thing as ADODB with the refernce
    "Microsoft ActiveX Data Objects 2.8 Library".
     
    Raymon, Aug 9, 2012
    #8
  9. Raymon

    Afshan

    Joined:
    Mar 27, 2014
    Messages:
    1
    Likes Received:
    0
    Could anyone help me to create ADODB recordset almost same as example mentioned above in VC++6.0
    Appreciate ur help!!
     
    Afshan, Mar 27, 2014
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andre Azevedo

    ADODB Command parameter error !

    Andre Azevedo, Oct 27, 2003, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    193
    Andre Azevedo
    Oct 27, 2003
  2. Empire City
    Replies:
    2
    Views:
    1,192
    Juan Gabriel Del Cid
    Oct 30, 2003
  3. Empire City
    Replies:
    0
    Views:
    251
    Empire City
    Oct 30, 2003
  4. MFRASER

    Using ADOdb recordset inside of .Net

    MFRASER, Mar 25, 2004, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    170
    MFRASER
    Mar 31, 2004
  5. Katit

    Dataset to ADODB.Recordset

    Katit, Sep 6, 2007, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    1,237
    Katit
    Sep 11, 2007
Loading...

Share This Page