i am working on an application and i need to have an update feature, but when i try to refresh the contents of my datagridview to view the update ive made, the old and updated records kept on stacking.

ive already tried the datagridview.datasource = nothing but nothing happened.

this is the code ive been using:

Private Sub editbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editbtn.Click



        Dim res = MessageBox.Show("Do you really want to save these changes?", "Alert!", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If (res = DialogResult.Yes) Then

            dbconnect()

            Dim sql As New SqlCommand("update productinfotbl set prodname = '" & prodnametbx.Text & "', genname = '" & gennametbx.Text & "', price = '" & pricetbx.Text & "', expiration = '" & exptbx.Text & "', critval = '" & crittbx.Text & "', stocks = '" & stocktbx.Text & "' where prodid = '" & prodidlbl.Text & "'", connect)
            sql.CommandType = CommandType.Text
            adapt.UpdateCommand = sql
            adapt.UpdateCommand.ExecuteNonQuery()

            Dim sql2 As New SqlCommand("select * from productinfotbl", connect)
            sql2.CommandType = CommandType.Text
            adapt2.SelectCommand = sql2
            adapt2.SelectCommand.ExecuteNonQuery()
            adapt2.Fill(dset, "info")
            dc()
            mainte.maintedt.DataSource = dset.Tables("info"

        Else
            Exit Sub
        End If 
    End Sub

Recommended Answers

All 2 Replies

if you can use of dataset(ado),so have simple way to do it:

dataset1.query_name.refreshall(dataset1.datatable)

this code is refreshing all of your table

well it is better to clear datagrid view

DataGridView.Rows.Clear()

Regards

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.