Dear All,

Pls. help me I have insert data to MS.Access and re-load data to DataGridView, it's always do at LoadAllData() but some time datagridview is not refresh.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\EmployeeDB\EmployeeDB.mdb;User Id=;Password=;"
        Dim conn as OleDbConnection
        conn = New OleDb.OleDbConnection(strConn)
        conn.Open()
        Dim cmdSave As OleDbCommand
        Dim strSave As String = String.Format("Insert Into Setup_Dept (DeptId,Department) Values ('{0}', '{1}')", txtCode.Text, txtName.Text)
        Try
            cmdSave = New OleDbCommand(strSave, conn)
            cmdSave.ExecuteNonQuery()
            LoadAllData()               
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString, Application.ProductName.ToString, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
End Sub


    Private Sub LoadAllData()
	Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\EmployeeDB\EmployeeDB.mdb;User Id=;Password=;"
        Dim conn as OleDbConnection
        conn = New OleDb.OleDbConnection(strConn)
        conn.Open()
        Try
            Dim strDept As String = String.Format("SELECT * FROM Setup_Dept Order by Department")
            Dim daDept As New OleDbDataAdapter(strDept, conn)
            Dim dsDept As New DataSet()

            ' Fill the dataset
            dsDept.Clear()
            daDept.Fill(dsDept, "tbEmployee")

            dgData.DataSource = Nothing              ' Clear ค่าใน DataGridView
            dgData.DataSource = dsDept               ' dsDept.DefaultViewManager 
            dgData.DataMember = "tbEmployee"

            dgData.Columns(0).Width = 75
            dgData.Columns(1).Width = 300
            daDept.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Try calling datagrid.refersh method after loading.

Try calling datagrid.refersh method after loading.

It doesn't work :(. Some body can help ???

Clearing all the rows and binding the grid again with new set of data?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.