VB To C# Conversion RRS feed

  • Question

  • Attempting to open an access database with DAO.  Here is a link to the VB code found in MSDN, but am struggling to convert that to C#.


    I can not figure out how to convert this line of code:

    Set ws = DBEngine.Workspace(0)

    I have tried both of the below, but get compile errors:

    ws = DBEngine.Workspace[0];

    DBEngine does not eist in the current context.

    I also tried to do

    ws = DAO.DBEngine.Workspace[0];

    which produces the compile error of 

    DAO.DBEngine does not contain a definition for Workspace.

    What should I do here?

    Friday, March 13, 2015 6:01 PM


All replies

  • Try 'Workspaces' (with the 's' at the end).

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Friday, March 13, 2015 6:45 PM
  • Try 'Workspaces' (with the 's' at the end).

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    No such luck.  When I use the intelli-sense or whatever it's called I 1st have to use DAO to even have DBEngine show as an option.  Then once I have DAO.DBEngine the only options that display are 

    Equals or referenceequals

    Friday, March 13, 2015 7:43 PM
  • Don't hold me to it, but I think you are going to have to use the DLL below. Maybe learn how to use it from a VB.NET prospective before trying to use it from a  C#.NET prospective. DAO is COM.




    Friday, March 13, 2015 8:27 PM
  • If I look up under the references in Solution Explorer in my project I have both Access & DAO active or this project



    And same scenario if I preface the line with 

    Microsoft.Office.Interop.Access.DBEngine -- I only have the options of Equals or ReferenceEquals

    Friday, March 13, 2015 8:36 PM
  • So you are telling me that if you do this or something similar to it to instanciate the object.

    objDbEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine();

    And you do this

    objDbEngine.    // to get the intelisense of all public methods and properties in the object that all you get is Equals and ReferenceEquals? I find that hard to believe.

    Friday, March 13, 2015 9:15 PM
  • You are correct my friend.  I apalgize for my mistake their.  I have as you specified above and this syntax, but this throws a compile error of DBEngine does not contain a definition for Workspaceand no etension method Workspace accepting a 1st argument of type DBEngine could be found.

    Microsoft.Office.Interop.Access.Dao.DBEngine objEngine;
    objEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine();
    Microsoft.Office.Interop.Access.Dao.Workspace wspace;
    Wspace = objEngine.Workspaces(0);

    Saturday, March 14, 2015 12:22 AM
  • Your problem is that the code in that link is supposed to go into an access database rather than a .net application.

    If you want to use interop:


    If you just want data which is in an access database then you can instead install a drive and use oledb.( looks for random link... )


    There's a code first entity framework provider here:


    I would consider converting the database to sql server ( express ).

    You could still keep the same access front end on that by linking the new sql server tables into your current access mdb.

    Maybe add whatever functionality you're considering into access.

    Often a better candidate for small applications than .net.

    Hope that helps.
    Recent Technet articles: Property List Editing; Dynamic XAML

    • Marked as answer by IndigoMontoya Saturday, March 14, 2015 3:04 PM
    Saturday, March 14, 2015 9:52 AM
  • I don't know what version of the Access Interop DLL you are using Office 2005, 2010 or , 2013 I don't know. Maybe you need to go back to a Office 2003 version or some previous version to see if the extension is implemented, because the extension may have been depreciated in more recent versions.


    You could write your own extension if you knew what the Workspace extension was doing. 

    Saturday, March 14, 2015 1:11 PM
  • @Andy Thank you for that article, I have been trying for a week now to get the syntax correct and reading the article the interop one 1st link, I got it done in about 10 minutes.
    Saturday, March 14, 2015 3:04 PM