Question connect Database on the solution explorer

Sumeet Jain

New member
Joined
Dec 30, 2011
Messages
1
Location
Dongargaon, India
Programming Experience
Beginner
Hi Guys,
I am new in VB.net & need your experience & help.

I am using Following Codes to connect my project to Access Database:-

VB.NET:
Public Class Login
    Dim con As New OleDb.OleDbConnection

    Dim ds As New DataSet

    Dim da As OleDb.OleDbDataAdapter

    Dim sql As String


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Sumeet Jain\Documents\Visual Studio 2008\Projects\Recharge_Management-1.0\Recharge_Management-1.0\Database1.mdb"

        con.Open()

        sql = "SELECT * FROM tblContacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "AddressBook")

        con.Close()

I want to use Database which is located on My Solution Explorer So My Question is that how can i connect Database which is located on the solution explorer
instead of using Data Source = C:\Users\Sumeet Jain\Documents\Visual Studio 2008\Projects\Recharge_Management-1.0\Recharge_Management-1.0\Database1.mdb"

Please help me i am in deep trouble ..
 
Make sure that you have set the Copy To Output Directory property of the database to Copy If Newer. You can then use "|DataDirectory|" as the folder path for the database in the connection string. That place-holder will be replaced by the system with the folder the EXE was run from at run time.
 

Latest posts

Back
Top