Insert data with dataset in web service

Hi,

I use a web service to populate a datagrid in a WPF window with customer data (I have simplified the example a bit). It works well but now I want to be able to add a new customer.

In the .vb
Private CustomerServiceClientInstance As New CustomerServiceReference.LetterServiceSoapClient

    Private Sub CustomerScreen_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

        'intialize data on the screen
        Call CustomerDataTable()
      
End Sub

    Private Sub CustomerDataTable()
        CustomerDataTableInstance = CustomerServiceClientInstance.GetCustomerList(New CustomerServiceReference.SecurityToken())
        dgCustomer.DataContext = CustomerDataTableInstance
    End Sub

in the .asmx

    <WebMethod()> _
    Function GetCustomerList As CUSTOMERDataTable

        Using taCustomers As New CUSTOMERTableAdapter
            Using dtCustomers As New CUSTOMERDataTable

                taCustomers.Fill(dtCustomers)

                'Return the list of customers
                Return dtCustomers
            End Using
        End Using
    End Function

It all works fine for retrieving data.

Now I want to be able to insert a new customer and I'm a bit stuck.

I created a webmethod

    Function SaveCustomer(ByVal CUSTOMERDataTable As CustomerDataSet.CustomerDataTable) As Boolean

        ' Save a new Customer to the database
        Dim CustomerTableAdapterInstance As New CustomerTableAdapter
        CustomerTableAdapterInstance.Insert(CustomerDataTable)

    End Function

Is this the right way to go?

in the .vb file I started with something like:

Private Sub btnSaveCustomer_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSaveCustomer.Click

              Dim dr As CustomerRow

                  dr = CustomerDataTableInstance.NewRow()
            dr.CUSTOMER_ID = Guid.NewGuid()
                  dr.CUSTOMER_FNAME = txtCustomerFname.Text
                  dr.CUSTOMER_LNAME = txtCustomerLname.Text
                  dr.CUSTOMER_EMAIL = txtCustomerEmail.text

    End Sub

How do I get the user input into a datatable and passed on to the database with the web service?

Any help is appreciated.
        ' Save a new Customer to the database
        Dim CustomerTableAdapterInstance As New CustomerTableAdapter
        CustomerTableAdapterInstance.Insert(CustomerDataTable)

    End Function
msglAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JoozefCommented:
Once you've created the CustomerRow instance and populated the fields, you need to do this:

  'Lock in the changes
  dr.EndEdit    

  'Add the new row to the DataTable
  CustomerDatetInstance.Rows.Add(dr)  


Then, when you call the webservice, the datatable passed to the Method "SaveCustomer" should be derived like this:

  'Send rows with changes only (Add/Mod/Del)
  wsInstance.SaveCustomer(CustomerDataTableInstance.GetChanges())


HTH,
Joe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msglAuthor Commented:
Thanks Joe,
it was helpful
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.