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


            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

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

            Exit Sub
        End If 
    End Sub

Recommended Answers

well it is better to clear datagrid view



Jump to Post

All 2 Replies

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


this code is refreshing all of your table

well it is better to clear datagrid view



Be a part of the DaniWeb community

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