Sync DataGridView to Database

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 10
Reputation: Aeterna is an unknown quantity at this point 
Solved Threads: 0
Aeterna Aeterna is offline Offline
Newbie Poster

Sync DataGridView to Database

 
0
  #1
Apr 27th, 2009
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..."



  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



  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.


  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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC