How to Connect to the Database in Visual Basic




(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)



(5.00 out of 5)





How to Connect to the Database in Visual Basic
Log in to answer.
Copyright © dBuggr LLC - All Rights Reserved.
nishantbaxi 2:09 am on February 27, 2010
Step 1Open your Visual Basic application and load the project into your workspace. Double-click the form in the Solution Explorer that will contain the database connection.
Step 2Right-click the form and select “Code View.” This opens your code page where you can create the database connection object.
Step 3Initialize the connection object variable. This is required before you can set the properties. The code below creates a connection object:
Dim conn As New OleDb.OleDbConnection
Step 4Load the connection object properties. This includes the database server name, database name and the driver. The code below illustrates how to set the properties:
conn.ConnectionString = “PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\myDatabase.mdb”
The code above sets the connection to a Microsoft Access file.
Step 5Open the connection. Once the connection has been defined, the last step required is to open the connection. The code below shows you how to open the new connection:
conn.Open()