Creating ADODB recordset in code

R

Raymon

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.
 
B

bradbury9

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#"
 
J

Jeff Johnson

(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?
 
B

bradbury9

El martes, 7 de agosto de 2012 18:54:55 UTC+2, Jeff Johnson escribió:
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
 
R

Raymon

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.
 
B

bradbury9

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
 
R

Raymon

El miércoles, 8 de agosto de 2012 04:57:14 UTC+2, Raymon escribió:

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".
 
Joined
Mar 27, 2014
Messages
1
Reaction score
0
Could anyone help me to create ADODB recordset almost same as example mentioned above in VC++6.0
Appreciate ur help!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top