I just installed the new Microsoft Visual Basic 2015. I want to build a database data entry using Visual Basic 2015. Here I want to show you how to create a new database connection on Visual Basic 2015. I use MS Access as the back end database and will be connected using OleDB connection.
The form design
Its a simple form with one button to execute or open the database connection. We can expand this later.
Public Class Form1 Dim provider As String Dim dataFile As String Dim connString As String Dim sql As String Public myconnection As OleDbConnection = New OleDbConnection Public dr As OleDbDataReader Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" dataFile = "E:\Solo_Drilling_BE.accdb" connString = provider & dataFile myconnection.ConnectionString = connString End Sub
The code inside Connect button
Private Sub btn_ConnectDatabase_Click(sender As Object, e As EventArgs) Handles btn_ConnectDatabase.Click myconnection.Open() MessageBox.Show(myconnection.State.ToString) End Sub