0

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
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by M.Waqas Aslam
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.