none
Data Access via WebService - I need a push in the right direction RRS feed

  • Question

  • I don't know if this is the correct forum so please direct me otherwise if it is not. I am new to .NET and webservices and need a little direction please.

     

    I am working on an VB application which is accessing data on my SQL Server via a web service.  My proof of concept application is quite simple.

     

    I have one table in my database called Listing. In my WebService solution I have one Dataset called DataSetOffice which contains two DataTables called listing and listing_entry. listing has one TableAdapter called listingTableAdapter.  listingTableAdapter has the standard GetData and Fill functions with secondary GetDataByID and FillByID functions. These take one paramater with is the id of a record. listing_entry has one TableAdapter with the standard GetData and Fill functions.

     

    Here is the code for my WebService

     

    Code Snippet

    Dim ListingAdapter As New DataSetOfficeTableAdapters.listingTableAdapter

    Dim ListingEntryAdapter As New DataSetOfficeTableAdapters.listing_entryTableAdapter

     

    _

    Public Function GetListingData() As DataSetOffice.listingDataTable

        Return ListingAdapter.GetData

    End Function

     

    _

    Public Sub UpdateListingData(ByVal ListingChanges As DataSetOffice.listingDataTable)

         ListingAdapter.Update(ListingChanges)

    End Sub

     

    _

    Public Function GetListingEntryData() As DataSetOffice.listing_entryDataTable

       Return ListingEntryAdapter.GetData

    End Function

     

     

    _

    Public Function GetListingDataByID(ByVal ID As String) As DataSetOffice.listingDataTable

         Return ListingAdapter.GetDataByID(ID)

    End Function

     

     

    In my VB app I have:

     

    Code Snippet

    Dim ListingData As New localhost.DataSetOffice.listingDataTable

    Dim ListingEntryData As New localhost.DataSetOffice.listing_entryDataTable

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

         Dim ws As New localhost.Service()

         Dim nCount

         ws.Credentials = System.Net.CredentialCache.DefaultCredentials

         ListingEntryData.Merge(ws.GetListingEntryData)

         DataGridView1.DataSource = ListingEntryData

     

         txtFirstName.DataBindings.Add("Text", ListingData, "contact_firstname")

         txtLastName.DataBindings.Add("Text", ListingData, "contact_lastname")

         txtAddress.DataBindings.Add("Text", ListingData, "contact_address")

         txtCity.DataBindings.Add("Text", ListingData, "contact_city")

    End Sub

     

    Which properly fills my DataGridView

     

     And

    Code Snippet

    Private Sub DataGridView1_RowEnter(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.RowEnter

     

       If Me.Visible And DataGridView1.ContainsFocus Then

          Dim selectedRowCount As Integer = _

          DataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)

          If selectedRowCount = 1 Then

             Dim ID As String

             ID = DataGridView1.SelectedRows(0).Cells("ID").Value().ToString

             Dim ws As New localhost.Service()

             ws.Credentials = System.Net.CredentialCache.DefaultCredentials

             ListingData.Clear()

             ListingData.Merge(ws.GetListingDataByID(ID))

     

          End If

       End If

    End Sub

    Which fills the TextBoxes on my form.

     

    What I cannot figure out is how to change the data in the TextBoxes and get it to update DB via my UpdateListingData Webservice. I know it can work because ListingData rather than ListingEntryData was my original datasource for my datagridview and my update code (see below) worked fine.

     

    Code Snippet

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

       Dim nCount As Integer

       nCount = ListingData.Count()

     

       If nCount = 1 Then

          Dim ws As New localhost.Service

          ws.Credentials = System.Net.CredentialCache.DefaultCredentials

          ws.UpdateListingData(ListingData)

       End If

    End Sub

     

    I'm guessing that the changes to my textfields aren't getting reflected in my ListingData DataTable and I can't find how to make that happen.  I've tried creating a BindingSource and using ListingData as the data source but I can't make that work. I've tried getting the DataSet of ListingData but it doesn't appear to exist and I can't figure out what the parent of ListingData is. I'm stuck.

     

    1) can someone point me in the right direction please?

    2) are there any good books that simplify the explanation of this.  Most of the articles I find online talk about how to use DataTables, DataSets, BindingSources, etc.. but these don't seem applicable when using WebServices since I can't make any of them work and many of the properties and methods of my WebService derived objects don't seem to work right.

    3) help?

     

     

     

     

    Friday, June 22, 2007 4:59 PM