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.
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:
For Each row As DataRow In myDataTable
MessageBox.Show(row("ZipCode").ToString())
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.