Click here to Skip to main content
12,511,665 members (47,186 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Im using vb 2012. Please help!
Posted 19-Feb-13 0:33am
navin ks1.6K
Updated 19-Feb-13 6:10am
v2
Comments
jonlink01 19-Feb-13 6:34am
   
which version of MS access you are using..
navin ks 19-Feb-13 6:37am
   
MS access 2007
navin ks 19-Feb-13 6:37am
   
thats my todays task.. help
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Here is the code snippet:

Dim cn As New OleDbConnection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Data.mdb;Persist Security Info=True"
cn.Open()
cn.Close()

Also, you can study this tutorial:
http://www.geekpedia.com/tutorial158_Connect-to-Access-Database-in-Visual-Studio-.NET.html

Finally, I suggest that you find a good book or a tutorial on ADO.NET. :)
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Use MS Access connection string
http://www.connectionstrings.com/access[^]

or you can create it from visual studio automatically
connection-string-from-visual-studio

Basic steps for database connectivity
MSDN
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

using System.Data.OleDb;
 
OleDbConnection con = new OleDbConnection();
            con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;
Persist Security Info=False;";
            con.Open();
            string query = "select * from clienttable";
            OleDbCommand cmd = new OleDbCommand(query, con);
            OleDbDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
            dataGridView1.Show();
            con.Close();

You can amend the above code as per your requirements. We have used OLDB method to get the data from data base to your gridview.

Let me know if you face any problems.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100