Step 1. Add reference to system.data in your code
Click project->Add Reference
Select .Net tab
Select System.Data
Now click Ok.
Step 2. before Public Class Form1, write
Imports System.Data
Step 3. In Form load event
Dim Con As new OleDb.OleDbConnection
Step 4. Now write next
Con.Connectionstring=”PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydatabase.mdb”
End Sub
Step 5. Open the connection to database with
Con.Open()
and display a msgbox to test the successful connection
msgbox(“the connection is opened”)
Step 6. Create new dataset and data adapter.
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Step 7. Pass new sql query to the data adapter
Dim sql As String
sql=”SELECT * FROM mydatabasetable1”
da=New OleDb.OleDbDataAdapter(sql,con)
This is how your Code should look like
Finally Fill the dataset with data.
da.Fill(ds,”mybase”)
This connects the database to dataset and fills it. Just that the data can’t be seen till now by anyone since it is not binded to any user viewable control.
txtFirstName.Text = ds.Tables("mydatabasetable").Rows(0).Item(1)
for further reading…http://www.homeandlearn.co.uk/NET/nets12p6.html
Final sample code::::::
Private Sub Frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim conn As New OleDb.OleDbConnection |