.NET Framework - Creating ADODB recordset in code

Asked By Raymon on 07-Aug-12 03:20 AM
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.




bradbury9 replied to Raymon on 07-Aug-12 04:43 AM
El martes, 7 de agosto de 2012 09:20:16 UTC+2, Raymon  escribi=F3:

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

BTW, it is is first google result for "adodb recordset c#"
Jeff Johnson replied to bradbury9 on 07-Aug-12 12:54 PM
I did not see anything in that link that talked about creating a recordset
from scratch, which is what the OP is asking about.
Jeff Johnson replied to Raymon on 07-Aug-12 12:55 PM
May I ask what this legacy requirement is? Are you going to pass the
Recordset to a COM object?
bradbury9 replied to Jeff Johnson on 07-Aug-12 01:51 PM
El martes, 7 de agosto de 2012 18:54:55 UTC+2, Jeff Johnson  escribi=F3:
=20


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

Dim rsInputBuffer As New ADODB.Recordset
rsInputBuffer.CursorLocation =3D 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:

veX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data O=
bjects 2.8 Library"

http://social.msdn.microsoft.com/Forums/pl-PL/Vsexpressvb/thread/f84cdc9c-f=
684-46d6-9b6f-757d047b00d5
Raymon replied to Jeff Johnson on 07-Aug-12 10:57 PM
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.
bradbury9 replied to Raymon on 08-Aug-12 04:49 AM
El mi=E9rcoles, 8 de agosto de 2012 04:57:14 UTC+2, Raymon  escribi=F3:

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

- 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 A=
ctiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Dat=
a Objects 2.8 Library""

Have you tried changing the reference? It may work in Framework 4.0
Raymon replied to bradbury9 on 09-Aug-12 12:37 AM
ADOR object model.
That's not the same thing as ADODB with the refernce