We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unable to update to database

I’m fairly new to VB .net so bear with me. I’ve tried all I other recourses to keep from bothering you with this question. I am using an SQL database with data binding and a VB windows App. I am having a problem with getting the table to update to the database. I am using textboxes to enter data into the grid. I am using the textboxes instead of the grid to facilitate data entry via barcode scanners. I have to enter a various number of rows the grid before the update is needed. The data is populating to the table and grid, but I am unable to get the data to update to the database. I have read that sometimes you must update the master and Detail record to the database at one time. At this point, I don’t know how to do that because I have to update the master record to the database to acquire the transaction number for the detail records. I have tried several suggestions from other forums, but have not succeeded as of yet. Because the Grid is a Syncfusion grid, I thought you would be able to assist better than the others. Can you help? Details: The Dataset is DsCrate1 Master Table: Package (includes: transactionNo, PackageNo, PalletNo) Detail Table: Crate_Details (includes: transcationNo, Item_Number, Date, Quantity) The transaction number is the related field. I have tried to update just the table by itself, but it will not update either. Here is the code I have been using to try to update the dataset: Public Sub UpdateDataSet() ''Create a new dataset to hold the changes that have been made to the main dataset. Dim objDataSetChanges As DsCrate = New DsCrate ''Stop any current edits. Me.BindingContext(DsCrate1, "Package").EndCurrentEdit() Me.BindingContext(DsCrate1, "Crate_Details").EndCurrentEdit() ''Get the changes that have been made to the main dataset. objDataSetChanges = CType(DsCrate1.GetChanges, DsCrate) ''Check to see if any changes have been made. If (Not (objDataSetChanges) Is Nothing) Then Try ''There are changes that need to be made, so attempt to update the datasource by ''calling the update method and passing the dataset and any parameters. Me.UpdateDataSource(DsCrate1) DsCrate1.Merge(objDataSetChanges) DsCrate1.AcceptChanges() Catch eUpdate As System.Exception ''Add your error handling code here. Throw eUpdate End Try ''Add your code to check the returned dataset for any errors that may have been ''pushed into the row object''s error. End If End Sub

3 Replies

AD Administrator Syncfusion Team March 18, 2004 03:46 PM UTC

I may be wrong, but it looks like you are trying to get the changes from DsCrate1, and then merge them back into the same DsCrate1. Wouldn''t it be sufficient just to call DsCrate1.AcceptChanges? Again, I may be missing some point here. Once you have the DataSet updated, normally you have this through some ''Adapter'' class. You would then call adapter.Update to push the changes in your dataset back to the database.


WG Wes Goad March 18, 2004 04:59 PM UTC

I''m sorry Clay! I didn''t put that sub in when I originally sent in the question. I''ve coded this to try to update the adaptor together and separately, but like I said before it will not update. THanks for the response! Here''s the rest of the code: Public Sub UpdateDataSource(ByVal ChangedRows As DsCrate) Try ''The data source only needs to be updated if there are changes pending. If (Not (ChangedRows) Is Nothing) Then ''Open the connection. Me.SqlConnection1.Open() ''Attempt to update the data source. sqlPackage.Update(ChangedRows) sqlDetails.Update(ChangedRows) End If Catch updateException As System.Exception ''Add your error handling code here. Throw updateException Finally ''Close the connection whether or not the exception was thrown. Me.SqlConnection1.Close() End Try End Sub


AD Administrator Syncfusion Team March 18, 2004 05:40 PM UTC

Instead of Me.UpdateDataSource(DsCrate1) DsCrate1.Merge(objDataSetChanges) DsCrate1.AcceptChanges() try DsCrate1.AcceptChanges() Me.UpdateDataSource(DsCrate1)

Loader.
Live Chat Icon For mobile
Up arrow icon