Results 1 to 2 of 2

Thread: Database book sample code not saving changes to the database

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    49

    Database book sample code not saving changes to the database

    Hi Everyone,

    I'm using the book titled "Database Programming with Visual Basic® .NET and ADO.NET: Tips, Tutorials, and Code".

    I'm going through the chapter that has me do data binding by setting the properties of a DataGrid and TextBoxes.

    It had me drag a DataAdapter onto the form and had me generate a DataSet. This part works fine. It also had me set the binding through the Text propert of each TextBox. This also works fine as it displays the correct data as the user navigates through the DataGrid.

    I think there may be something missing from the code samples in the book because saving the data back to the database is not working and even no errors are reported.

    Here is the code from the book that writes changed text in the TextBoxes back to SQL Server. Can you tell me what the book is missing?

    Code:
        Private Sub SaveRecord()
    
            ' Use the BindingContext class to end current editing so that we can update the server.
            '--------------------------------------------------------------------------------------
            BindingContext(DataSetCustomerIndividual, "Customers").EndCurrentEdit()
    
            ' Perform the requested task at the dataset level using the data adapter.
            '------------------------------------------------------------------------
            SqlDataAdapterCustomerIndividual.Update(DataSetCustomerIndividual, "Customers")
    
            ' By accepting the changes, the data gets sent back to the server.
            '-----------------------------------------------------------------
            DataSetCustomerIndividual.AcceptChanges()
    
        End Sub
    Thanks.

    Truly,
    Emad

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    49

    Re: Database book sample code not saving changes to the database

    Additional Notes:

    There are 2 DataAdapters and also a total of 2 DataSets.

    I looked at the DataSet names in the DataSet designers and they both had the same name. I believe this is causing the problem.

    My question is how do I rename the Dataset name in one of the DataSets without messing up the entire application? I tried to re-name one of them and all kinds of errors appeared so I had to re-name it back to the original name called "Customers". I was hoping to get it named "CustomersIndividual".

    Truly,
    Emad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width