| | |
Sync DataGridView to Database
![]() |
•
•
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?
Views: 832 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access accessdenied administrator application array arrays basic browser build button buttons c# captcha center check client code combobox component connection control convert cpu crystal crystalreport data database datagrid datagridview date datetimepicker design designer dissertation dissertations dropdownlist error excel file folder google image images insert lib listview login mobile ms msaccess net path picturebox port print printing printpreview problem problemwithinstallation read regex release save searchbox security serial server settings sharepoint sms socket sorting sql statement studio syntax textbox time timer upload user validation vb vb.net vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser windows wpf xml





