Question Datagridview Refresh not functioning

jacobfscott

New member
Joined
Jan 29, 2010
Messages
2
Programming Experience
Beginner
I am working on a simple application. I am opening a dialog from a menu that populates a datagridview with data from a dataset. I am using Visual Studio and and .mdf file. I have set the .xsd file with the default stuff (ie, I dragged the database from the server explorer to the .xsd file. Anyway, I have a button that is enabled when I click on one of the rows of the datagridview. When clicked, I am firing a SQL command to delete the selected row. The SQL works. I am unable to refresh the data. I will include the code. It is simple. My issue is that I cannot quite figure out why I cannot get the data in the dataset to change unless I actually close and reopen the application. I know this is about the table adapter. I have tried different variations of the update,clear and other methods. Most of my programming experience is with ASP and VB code behind.

VB.NET:
        Dim qSQL As String
        Dim sqlcmd As New SqlCommand
       
        qSQL = "DELETE FROM LocationMaster WHERE LocationID=" & DataGridView1.CurrentRow.Cells(0).Value

        oConn.Open()
        sqlcmd.CommandText = qSQL
        sqlcmd.CommandType = CommandType.Text
        sqlcmd.Connection = oConn
        sqlcmd.ExecuteNonQuery()
        oConn.Close()

        

        lbl_delete.Visible = True
        lbl_delete.Text = "Deleting Location: " & DataGridView1.CurrentRow.Cells(1).Value

        Me.InventoryMainDataSet.LocationMaster.Clear()
        Me.LocationMasterTableAdapter.Fill(Me.InventoryMainDataSet.LocationMaster)

        Me.DataGridView1.DataSource = Nothing
        Me.DataGridView1.DataSource = Me.InventoryMainDataSet.LocationMaster

Thanks for any help.
 
Work around

So I did some more reading and decided that it might be easier to fill or refill the dataset with my own code instead of using the dataset .xsd. It is working nicely. I am still interested in understanding that tableadapter but I do not have an issue currently.
 
Back
Top