DAO in C# Express

I am just starting to learn c# (I am from vb.net background) but I am having problems using DAO OpenDatabase and OpenRecordset when using c# express. I am not sure if this is related to database limitation of c# express. I have the following code in c# (which I converted from vb.net):

DAO._DBEngine dbEng = new DAO.DBEngineClass();
DAO.Workspace ws = dbEng.CreateWorkspace("", "admin", "", DAO.WorkspaceTypeEnum.dbUseJet­Wink;
DAO.Database db = ws.OpenDatabase(DBFileName, false, false, "");
DAO.Recordset rs;
rs = db.OpenRecordset("select * from Folder where FolderNo=0", "", "" ,"");

But I get the error "Operation is not supported for this type of object" at the OpenRecordset line. VB.net only have one mandatory parameter for OpenDatabase and OpenRecordset whereas c# has four mandatory parameters and the help files don't seem to give any indication on what those parameters should be.

My questions are:

1. Is the error a result of the database limitations of c#?
2. If c# can access the jet database via DAO, what parameters should be used? VB.net have optional parameters whereas putting null and "" in c# don't seem to help in the above OpenDatabase and OpenRecordset methods.

[1290 byte] By [mo.] at [2008-1-19]
# 1

1. Is the error a result of the database limitations of c#?

No. DAO is a COM object and C# Express shouldn't have any limitations on using COM.

DAO is really an old data access mechanism though. As long as you're learning C#, you'd be best off taking a look at ADO.NET as it's the preferred way of accessing databases in .NET. If you're looking to open a JET database, you can use the OleDb provider and supply the appropriate connection string.

2. If c# can access the jet database via DAO, what parameters should be used? VB.net have optional parameters whereas putting null and "" in c# don't seem to help in the above OpenDatabase and OpenRecordset methods.

The correct parameter to supply for missing COM parameters in .NET is Type.Missing. If you need a ref parameter, assign Type.Missing to an object variable and you can pass that variable as a reference. You would be better off migrating your code to ADO.NET though for most things.

Regards,
--Oren

OrenNovotny at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2

Oren - Thanks for the info.

mo. at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3
Poderia me dar um caminho de como acessar dbfs via ADO.net ?
Epilif at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified