Results 1 to 2 of 2

Thread: Puting Dataset results in an array and comparing them

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Puting Dataset results in an array and comparing them

    Right now I have a function that takes the Lons and Lats of two different Zip Codes (from two text boxes) and tells me the difference in miles. Now what I want to do is eliminate on of the text boxes so that I have a single start Zip Code, which I want to compare to 5 Zip Codes being returned from my dataset. It's a little confusing so let me demonstrate it this way.

    Currently my function does this:

    Zip0 to Zip1 is 36 miles.

    I want my function to do this:

    Zip0 to Zip1 (from the ds) is 36 miles
    Zip0 to Zip2 (from the ds) is 50 miles
    Zip0 to Zip3 (from the ds) is 45 miles
    Zip0 to Zip4 (from the ds) is 60 miles
    Zip0 to Zip5 (from the ds) is 20 miles

    I think I am going to need an array to store the numbers from the dataset in and then do a For Each Item to do my comparison but I have no idea of how to get started. My goal is to list them in order of least to greatest distances.

    Any help will be appreciated.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Puting Dataset results in an array and comparing them

    The data is already in a DataTable so you can iterate over that just as easily as you can an array.
    VB Code:
    1. For Each row As DataRow In myDataTable
    2.     MessageBox.Show(row("ZipCode").ToString())
    3. Next row
    You can get whatever field values you need from the row inside the loop and do whatever you need to do with them. Note that a DataSet is a container for DataTables and the DataRelations between them. You can access the individual DataTables through the Tables property. If you are only using a single DataTable then having a DataSet is pointless. If that's the case you should forget about the DataSet altogether and just work with a DataTable. You can pass a DataTable to the Fill method of a DataAdapter just as you would pass a DataSet.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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