How to Connect Database Access 2007 in VB.Net


In this tutorial we will create a program to demonstrate on how to connect a database access using a binding source.

Step 1: Create your blank database and table name
Name your table name
Then add data field


Step 2: Create your program design, you need 5 Labels, 5 Textbox, 6 Buttons and 1 Datagridview, Please refer the layout in the first image above .


Step 3: Go to you Data Sources Tab, in the right side of your screen then click Add New Data Source

 Select Database, click next
Then Dataset, click next
Click New Connection
Browse your database file name then test your connection and click ok then Next, If some dialogs comes up with a just click the button Yes.
Check the tables and views then click finish.
Step 4: Click your DatagridView then click the arrow in the right upper side of datagrid and choose your data source
Click ProfileBindingSource
Step 5: Click the first textbox, go to properties and find databindings
Click the Text then choose the corresponding field name, Do this in other textbox with the fieldnames
Step 6: Open the code editor then type this code

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ProfileTableAdapter.Fill(Me.ConnectDBDataSet.profile)
    End Sub
   
    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        ProfileBindingSource.MovePrevious()
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        ProfileBindingSource.MoveNext()
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        ProfileBindingSource.AddNew()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        On Error GoTo ErrCapture
        ProfileBindingSource.EndEdit()
        ProfileTableAdapter.Update(ConnectDBDataSet.profile)
        MsgBox("Successfully Saved!")
ErrCapture:
        Exit Sub
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        ProfileBindingSource.RemoveCurrent()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class

Run the program. Final Output


How to Connect Database Access 2007 in VB.Net How to Connect Database Access 2007 in VB.Net Reviewed by code-dev on 9:47 PM Rating: 5

No comments:

Powered by Blogger.