Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Im using vb 2012. Please help!
Posted
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

Here is the code snippet:

C#
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. :)
 
Share this answer
 
v2
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
 
Share this answer
 
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900