Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 6 years ago

MS Access and Visual Studio?

Hello, I'm trying to develop a small app that uses an Access Database file. I know EF and Datasets aren't really built to support Access, but in my case i don't have an option to switch over to SQL Server. I want to know what would be the best method to use to link my database to my c# project so that I can query results from my project app. Could someone point me to some tutorials or something? Thank you.

2 Answers

Relevance
  • 6 years ago
    Favorite Answer

    Nearly every tutorial out there uses the Northwind Access MDB as the database to connect to when using VS. Your connection string to the data is all that will really change.

    Just go to the Serve explorer and add a new connection. IN the provider dialog click on the MS Jet 4.0 OLE DB provider and then browse for your access mdb file. Type in the USER ID and PW (if any) you use to access the MDB file and you should have full access to the data base from within your project.

    You can also drag and OleDbConnection object right onto any form or desginer and set the connection String prop to connect to your MDB.

    IN code you can connect using the System.Data.OleDb.OleDbConnection object.

    A connection string for access will look something like this

    @"Provider=Microsoft.Jet.OLEDB.4.0;" +

    @"Data source= C:\Documents and Settings\username\My Documents\AccessFile.mdb";

    just remember the you will need to .Open() your connection and when you are done you should .Close() the connection immediately!

    Hope this helps...

  • 6 years ago

    Yeah, your going to have top use ADO... here is a link to some examples...

    http://msdn.microsoft.com/en-us/library/dw70f090.a...

Still have questions? Get your answers by asking now.