Monday, April 23, 2012

How to connect to MS- Access in VB.net


Dim conn As New OleDb.OleDbConnection
         conn.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Love.mdb"
        Try
             conn.Open()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "connection to access failed")

        End Try
 Dim comm As New OleDb.OleDbCommand

  comm.CommandText = "delete from customer where ID = " & TextBox1.Text

         comm.Connection = conn

        If  comm.ExecuteNonQuery() = 1 Then
            MessageBox.Show("Successful")
        End If


         comm.CommandText = "select ID from customer where contact = '" & TextBox3.Text & "'"
         comm.Connection = conn

        Dim dr As OleDb.OleDbDataReader =  comm.ExecuteReader()

        If dr.HasRows Then
            Do While dr.Read()
                MessageBox.Show("The Customer id is " & dr("ID"))
            Loop

        End If


       conn.Close()


1 comment:

  1. DO you want to build your aptitude skills in short time.
    must try this website
    http://www.kidsfront.com/competitive-exams/quantitative-aptitude-practice-test.html

    ReplyDelete