none
Connecting to MS Access DB with .net 2005 RRS feed

  • Question

  • Hey all -
    I have a question.  I am trying to connect to a MS Access DB using VB .Net 2005.  I found this link (http://support.microsoft.com/kb/821765) but that only works for .NET 2003.  I don't have the OleDbDataAdapter option in 2005.  I can load the Access DB in the Server Explorer, but that is as far as I can get.  Hate to be that guy, but can someone give me general step by step instructions on how to connect to an Access DB?  Thanks a million.

    Sunday, November 4, 2007 5:54 AM

Answers

All replies

  • OleDbDataAdapter is part of the System.Data.OleDb library. You can either fully qualify the reference (e.g. System.Data.OleDb.OleDbDataAdapter) or add an Imports statement to the top of your module (e.g. Imports System.Data.OleDb).

     

    Monday, November 5, 2007 1:37 PM
  • My only issue is that I do not have OleDbDataAdpter as a choice in my Data library.  Is there another way to drag a data set or datalink to the form and establish the connection that way?
    Tuesday, November 6, 2007 2:03 PM
  • Maybe this will help-this connects a database table to a datagridview

     

     

    You can get other connection strings from:http://www.connectionstrings.com

     

    Code Block

    Access 2007

    //Setup the connection string

    string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +@"C:\DATA\MyDB.accdb;Persist Security Info=False;";

     

    // create an open the connection

    OleDbConnection conn = new OleDbConnection(conString);

    OleDbCommand command = new OleDbCommand();

    command = conn.CreateCommand();

     

    // create the DataSet

    DataSet ds = new DataSet();

     

    // run the query

    command.CommandText = "SELECT * FROM TABLE WHERE COLUMN= '1'";

    OleDbDataAdapter adapter = new OleDbDataAdapter();

    adapter = new OleDbDataAdapter(command);

    adapter.Fill(ds);

     

    // close the connection

    conn.Close();

     

    // set the grid's data source

    dataGridView1.DataSource = ds.Tables[0];

     

     

     

    Tuesday, November 6, 2007 2:42 PM
  • OleDbDataAdapter is a member of System.Data.OleDb, which is included with .NET. It should be available to you.

    The other method you mentioned uses the Data Source Configuration Wizard.

    Tuesday, November 6, 2007 3:05 PM
  • I was able to connect to the Data Sources.  I just want to key in the customer information on the form, click a save button, and save that data to the DB.

    My DB is call testdb.mdb
    I have two tables:
    CustomerInfo-
    Field:
    Firstname
    Lastname
    Address
    City
    State
    Zip
    CustomerOrder-


    Connect to Access DB through data source.
    (Don't know the code)

    Update a row with the information from the text boxes.
    (Don't know the code)

    The MSDN sites suck b/c they give you a complete example.  Please help!!!!
    Wednesday, November 7, 2007 4:08 AM