| | |
Sync DataGridView to Database
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 0
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..."
There's my code for adding and removing rows. Heres my code for updating.
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?
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)
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
VB.NET Syntax (Toggle Plain Text)
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
VB.NET Syntax (Toggle Plain Text)
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?
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
Other Threads in the VB.NET Forum
- Previous Thread: Saving and displaying data on datagrid!
- Next Thread: Interact with windows popup boxes?
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic box button buttons center check code component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist excel fade file-dialog firewall folder ftp generatetags hardcopy image images input insert intel isnumericfuntioncall math monitor navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port problem problemwithinstallation project record reports" savedialog searchvb.net select serial shutdown string survey tcp temp temperature text textbox timer toolbox trim updown user useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





