Posted by: Sourav | March 25, 2015

Run a sql query on access from Visual Basic 2012

Imports System.Data.OleDb

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim myconn As OleDbConnection
        myconn = New OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Sourav.MDB”)
        ‘MessageBox.Show(“Connection successful”, “Sourav”)

        Dim mycommand As OleDbCommand
        mycommand = myconn.CreateCommand()
        mycommand.CommandText = “select count(*) as emp from EmployeeMaster”
        Dim count As Object = mycommand.ExecuteScalar()
        MessageBox.Show(“There are ” & count & ” rows are there in the employeemaster table”, “Sourav”)

    End Sub
End Class


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: