954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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?

Aeterna
Newbie Poster
19 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You