Convert Dataset to Recordset in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to convert a dataset to an ADODB.Recordset. I create the sxl
file and open it in VB.NET by using:
Dim rs as ADODB.Recordset
rs.Open("C:\files\xslfile.xsl")

I want to do this same thing in C#. The open method in C# takes several
additional parameters in addition to the xsl file:
rs.Open("C:\files\xslfile.xsl", object ActiveConnection,
ADODB.CursorTypeEnum, ADODB.LockTypeEnum, int Options)

While it may seem very obvious to everyone, I am having trouble providing
valid arguments to make this method work.

Any help is greatly appreciated.

Robert
 
I am trying to convert a dataset to an ADODB.Recordset. I create the
sxl file and open it in VB.NET by using:
Dim rs as ADODB.Recordset
rs.Open("C:\files\xslfile.xsl")

I want to do this same thing in C#. The open method in C# takes
several additional parameters in addition to the xsl file:
rs.Open("C:\files\xslfile.xsl", object ActiveConnection,
ADODB.CursorTypeEnum, ADODB.LockTypeEnum, int Options)

While it may seem very obvious to everyone, I am having trouble
providing valid arguments to make this method work.

Any help is greatly appreciated.

Robert

Hi Robert.

This is how I use an Access database:

string strConnection;
string strQuery;

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;";
strConnection += " Data Source=";
strConnection += this.m_strDBName;
strConnection += ";";

strQuery = "SELECT * FROM " + this.m_strTableName + " WHERE blnCompany
= True";

adCON.Open(strConnection, "", "", 0);
adRS.Open(strQuery, adCON, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic ,0);

Can you pick the bones from that?
 
Thanks for the reply.

I am opening a recordset from a xsl file, not a database. How would you do
that in C#?

Robert
 
Marathoner said:
Thanks for the reply.

I am opening a recordset from a xsl file, not a database. How would you do
that in C#?
<snip>

Why not use the OleDb .net classes ?

You can use the same provider as you would for ADODB.Connection.
 
Thanks.
I must not understand recorsets and xml. In VB.NET I can open a recordset by:
rs.Open("C:\Files\MyXsl.xsl")
I have written this applicaton in C# and the addional arguments are
required. I do not need a connection. I have a xsl file created from a
dataset. I just need to populate the recordset with this data.
If I can't get this resolved, I may have to rewrite this in VB.NET even
though I want to continue my learning exprience in C#.

Robert
 
Thanks for the reply.

I am opening a recordset from a xsl file, not a database. How would
you do that in C#?

Robert

I wouldn't, I would convert the Excel file into an Access database
since in my view it's a better way to keep data.

A quick look at help shows a subject 'Excel, Importing Data' which may
help, it seems quite similar with an additional step to select the
correct worksheet.
 
I agree if I were using Excel .xls files. This is a .xsl file which is an
ADO Recordset format for defining the schema.

Robert
 
I agree if I were using Excel .xls files. This is a .xsl file which
is an ADO Recordset format for defining the schema.

Robert

Sorry, must have Excel on my mind :-)

The example I gave included the extra parameters, did you try them?
 
No. I have the data. I do not need to open a recordset and obtaion data
from a database. The data is coming form the dataset passed into the
procedure. I am creating a recordset from the data in the dataset. As part
of this process, I create a .xsl file which comtains both the schema and the
data. I need to open the recordset with this .xsl file. VB.NET is like this:

rs.Open("C"\Files\MyXslFile.xsl")

I want to do it in C# which is like this:

rs.Open("C:\files\xslfile.xsl", object ActiveConnection,
ADODB.CursorTypeEnum, ADODB.LockTypeEnum, int Options)

Since I do not need a connection, cursor type, lock type, or any options,
how is this accomplished?
 
Robert,

One of the major differences between VB.Net and C#.Net that causes problems
with interop and things like you're trying to do is that there are no
optional parameters in C#.

As a result you must supply a value for all parameter values of a method or
class call.

With interop I've used oMissingValue as defined below for parameters that
don't require actual values.

object oMissingValue = Type.Missing; &
object oMissingValue = System.Reflection.Missing.Value;

Hope this helps.

Barry
in Oregon
 
Back
Top