Connecting to MS Access USing VB.NET

Mohit

Member
Joined
Nov 9, 2004
Messages
6
Programming Experience
3-5
Hi i'm doing this for the first time. I need to connect to a ms Access database titled "temp.mdb" and preform a select statment and display the results of the statment. Can someone please give me an example in code and discribe what components i have to use ?

Thanks.
 
there are several ways to do it, you can do the whole thing in code, or you could "graphically" do it with the wizard in the data-adapter on the form.

Graphically
in the server explorer simply click 'Connect to Database' and pick the Microsoft Jet 4.0 OLE DB driver then in the next window locate the DB on your HDD and that'll add the Access DB to the server explorer where you simply select the Table(s) (or feilds in a table if you only want some and not all) and drag it to the form where the editor adds the connection object and the dataAdapter. then just configure the dataAdapter and finally built the dataset... boom your done, just bind any control(s) you want to get values from the DataSet.

Programmically:
ask neal, mzim, paszt they've posted numerous examples on how to do it programmically
 
I think this code help you: (Display data in a Datagrid)

VB.NET:
Dim con as OleDbConnection= New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server mappath("YourDataBase.mdb"))
Dim sql As String="Select * from YourTable"
Dim dta As OleDbDataAdapter= New OleDbDataAdapter
Dim cmd As New OleDbCommand= New OleDbCommand(sql,con)
dta.SelectCommand=cmd
Dim dst as New DataSet
dta.Fill(dst,"YourTable")
MyGrid.DataSource=dst
MyGrid.DataBind()
 
Back
Top