vb.net2015_slip23




Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim da As New OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim cmd As New OleDb.OleDbCommand
    Dim query As String
    Dim dbProvider As String
    Dim dbSource As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source=C:\Users\Ramdas\Documents\studentmdb.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        da = New OleDb.OleDbDataAdapter("select * from std", con)
        da.Fill(ds, "st")
        DataGridView1.DataSource = ds.Tables("st")
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim x As Integer
        query = "update std set sclass='tybca' where sclass='sybca'"

        cmd = New OleDb.OleDbCommand(query, con)
        Try
            x = cmd.ExecuteNonQuery()
            If (x) Then
                MsgBox("Data Updated")
            Else
                MsgBox("No data to update")
            End If
            ds.Tables.Clear()
            da = New OleDb.OleDbDataAdapter("select * from std", con)
            da.Fill(ds, "st")
            DataGridView1.DataSource = ds.Tables("st")
        Catch ex As Exception
            MsgBox("Exception Occured")

        End Try

    End Sub
End Class

No comments:

Post a Comment

Note: only a member of this blog may post a comment.