DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Sync DataGridView to Database (http://www.daniweb.com/forums/thread189112.html)

Aeterna Apr 27th, 2009 6:03 pm
Sync DataGridView to Database
 
I have datagridviews where I've removed the ability for users to edit them directly. I have made add and delete buttons for users to add rows and remove selected rows.

Occasionally, and I'm not sure why, I get the "Prepare: CommandText..." error, as well as "Update requires a valid ___Command..."



    Function AddRow(ByVal input As String, ByVal ds As DataSet, ByVal tablename As String, ByVal dgv As DataGridView)
        Dim NewRow = ds.Tables(tablename).NewRow()
        Dim Table = ds.Tables(tablename)
        NewRow.Item(1) = input
        Table.Rows.Add(NewRow)
        Return False
    End Function



    Function DeleteRow(ByVal selectedrows As DataGridViewSelectedRowCollection, ByVal ds As DataSet, ByVal dgv As DataGridView)
        For Each r As DataGridViewRow In selectedrows
            If Not r.IsNewRow Then
                dgv.Rows.RemoveAt(r.Index)
            End If
        Next
        Return False
    End Function
There's my code for adding and removing rows. Heres my code for updating.


    Function UpdateAccountTable()
        frmMain.AccountsTableAdapter.Update(frmMain.DsAccounts)
        Return False
    End Function
    Function UpdatePURLTable()
        frmPURL.ProfileURLsTableAdapter.Update(frmPURL.DsProfileURLs)
        Return False
    End Function
    Function UpdatePLocationTable()
        frmPLocation.ProfileLocationsTableAdapter.Update(frmPLocation.DsProfileLocations)
        Return False
    End Function
    Function UpdatePDescriptionTable()
        frmPDesc.ProfileDescriptionsTableAdapter.Update(frmPDesc.DsProfileDescriptions)
        Return False
    End Function


Let me know if I'm missing something. Thanks!

btw, is there any way to define a tableadapter as a type so I can make 1 function for updating?


All times are GMT -4. The time now is 11:55 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC