943,078 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1298
  • VB.NET RSS
Apr 27th, 2009
0

Sync DataGridView to Database

Expand Post »
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..."



VB.NET Syntax (Toggle Plain Text)
  1. Function AddRow(ByVal input As String, ByVal ds As DataSet, ByVal tablename As String, ByVal dgv As DataGridView)
  2. Dim NewRow = ds.Tables(tablename).NewRow()
  3. Dim Table = ds.Tables(tablename)
  4. NewRow.Item(1) = input
  5. Table.Rows.Add(NewRow)
  6. Return False
  7. End Function



VB.NET Syntax (Toggle Plain Text)
  1. Function DeleteRow(ByVal selectedrows As DataGridViewSelectedRowCollection, ByVal ds As DataSet, ByVal dgv As DataGridView)
  2. For Each r As DataGridViewRow In selectedrows
  3. If Not r.IsNewRow Then
  4. dgv.Rows.RemoveAt(r.Index)
  5. End If
  6. Next
  7. Return False
  8. End Function
There's my code for adding and removing rows. Heres my code for updating.


VB.NET Syntax (Toggle Plain Text)
  1. Function UpdateAccountTable()
  2. frmMain.AccountsTableAdapter.Update(frmMain.DsAccounts)
  3. Return False
  4. End Function
  5. Function UpdatePURLTable()
  6. frmPURL.ProfileURLsTableAdapter.Update(frmPURL.DsProfileURLs)
  7. Return False
  8. End Function
  9. Function UpdatePLocationTable()
  10. frmPLocation.ProfileLocationsTableAdapter.Update(frmPLocation.DsProfileLocations)
  11. Return False
  12. End Function
  13. Function UpdatePDescriptionTable()
  14. frmPDesc.ProfileDescriptionsTableAdapter.Update(frmPDesc.DsProfileDescriptions)
  15. Return False
  16. 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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aeterna is offline Offline
19 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Saving and displaying data on datagrid!
Next Thread in VB.NET Forum Timeline: Interact with windows popup boxes?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC