Click here to Skip to main content
Rate this: bad
good
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.4K
Edited 19-Feb-13 6:10am
v2
Comments
jonlink01 at 19-Feb-13 6:34am
   
which version of MS access you are using..
navin ks at 19-Feb-13 6:37am
   
MS access 2007
navin ks at 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. Smile | :)
  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
0 OriginalGriff 375
1 Prakriti Goyal 242
2 Yogesh Kumar Tyagi 224
3 Sergey Alexandrovich Kryukov 158
4 CPallini 150
0 OriginalGriff 6,742
1 Sergey Alexandrovich Kryukov 5,479
2 Maciej Los 3,474
3 Peter Leow 3,313
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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