| | |
Sync DataGridView to Database
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
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 binary bing box button buttons center check code component connectionstring convert cpu crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp hardcopy image images insert isnumericfuntioncall login math memory mobile ms mssqlbackend mysql navigate net networking opacity output passingparameters peertopeervideostreaming picturebox1 port printpreview problemwithinstallation project record reports" reuse save savedialog serial soap storedprocedure string tcp temp text textbox timer toolbox trim update updown useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf





