I have query that updates the database but the problem was the datagrid is not updating.. i have to restart the program in order for the datagridview to take effect

Imports System.Data.OleDb

Public Class frmUsers

    Dim cnn3 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
    Dim sql2 As String

    Dim ds1 As New DataSet
    Dim adptr As OleDbDataAdapter

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim Command1 As New OleDbCommand

        Dim i2 As Integer
        Dim sql1 As String
        Dim Status As String

        Try
            Dim cnn3 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
            cnn3.Open()
            If ComboBox1.SelectedValue = "Admin" Then
                Status = "Admin"
            Else
                Status = "Student"
            End If
            sql1 = "INSERT INTO Users ([ID],[PASSWORD],[LASTNAME],[FIRSTNAME],[LOGINTYPE]) VALUES('" & txtUID.Text & "','" & txtUPassword.Text & "','" & txtULastname.Text & "','" & txtUFirstName.Text & "','" & Status & "')"
            Command1 = New OleDbCommand(sql1, cnn3)
            i2 = Command1.ExecuteNonQuery
            MessageBox.Show("Users Added Successfull")



        Catch ex As Exception
        End Try

    End Sub

    Private Sub btnback_Click(sender As Object, e As EventArgs) Handles btnback.Click
        Me.Hide()
        frmFaculty.Show()
    End Sub


    Private Sub frmUsers_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim cnn4 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
        sql2 = "Select * from Users"
        Try
            cnn4.Open()
            adptr = New OleDbDataAdapter(sql2, cnn4)
            adptr.Fill(ds1)
            DataGridView1.DataSource = ds1.Tables(0)
        Catch ex As Exception

        End Try

        cnn4.Close()
    End Sub

End Class

Edited 3 Years Ago by pritaeas: Moved to VB.NET

I suggest to use your code from frmUsers. Add it below MessageBox.Show("Users Added Successfull") from btnAdd. One more thing you don't need the ".show" on your MsgBox as it will pop up once the insert is done

MsgBox("Users Added Successfull")
 Dim cnn4 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
        sql2 = "Select * from Users"
        Try
            cnn4.Open()
            adptr = New OleDbDataAdapter(sql2, cnn4)
            adptr.Fill(ds1)
            DataGridView1.DataSource = ds1.Tables(0)
        Catch ex As Exception
        End Try
        cnn4.Close()

BindingSource binding = new BindingSource(); //req. by win forms
DataTable dt = new DataTable();
dt.Load(sql_command.ExecuteReader());
dgv.DataSource = dt;

Private Sub updatedgv()
        Dim conn As New MySqlConnection(My.Settings.myConn)
        Dim da As New MySqlDataAdapter
        Dim ds As New DataSet
        Dim str1 As String = "select * from tableName"
        da.SelectCommand = New MySqlCommand(str1, conn)
        da.Fill(ds)
        conn.Close()
        ProductDataGridView.DataSource = ds.Tables(0)
    End Sub
This article has been dead for over six months. Start a new discussion instead.