?
Solved

Make records repeat when using Datasets on ASP.NET page from SQL Server

Posted on 2007-07-24
24
Medium Priority
?
472 Views
Last Modified: 2013-11-26
Hi Experts,

I have the following VB.NET code on my ASP.NET page to return the results of a zip code search:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ZIPCode As String = "92352"
        Dim Miles As Double = 500
        Dim DatabaseConnection As String
        Dim DatabaseQuery As String
        DatabaseConnection = ConfigurationManager.AppSettings("DataConnect")
        DatabaseQuery = "SELECT Latitude, Longitude FROM dbo.tblZipCodes WHERE ZIPCode = '" + ZIPCode + "'"

        Dim zcdDB As New SqlDataAdapter(DatabaseQuery, DatabaseConnection)
        Dim ZIPCodes As New DataSet()
        zcdDB.Fill(ZIPCodes, "ZIPCodes")

        Dim ZIPExists As Boolean = Not (ZIPCodes.Tables("ZIPCodes") Is Nothing)
        If ZIPExists Then
            Dim Latitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Latitude")
            Dim Longitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Longitude")
            Dim zcdRadius As New ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles)
            DatabaseQuery = "" _
                & "      SELECT * FROM vwDealerLocator WHERE" _
                & "            Latitude >= " & zcdRadius.MinLatitude _
                & "            AND Latitude <= " & zcdRadius.MaxLatitude _
                & "            AND Longitude >= " & zcdRadius.MinLongitude _
                & "            AND Longitude <= " & zcdRadius.MaxLongitude _
                & "            AND CityType = 'D'"

            zcdDB.SelectCommand.CommandText = DatabaseQuery
            zcdDB.Fill(ZIPCodes, "Radius")
            Dim zcdDistance As New ZIPCodeDownload.DistanceAssistant()
            Dim thisRow As System.Data.DataRow
            For Each thisRow In ZIPCodes.Tables("Radius").Rows
                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)
               
                ' Display the results
                If Distance <= Miles Then

                    txtDealer.Text = thisRow("Dealer") + ", " + thisRow("Address01") + ", " + thisRow("Zip")
                    txtCity.Text = thisRow("City") + ", " + (Left(Distance.ToString, 3)) + " Miles"
                    'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)

                End If
            Next
            ' Clear the variables
            zcdRadius = Nothing
            zcdDistance = Nothing
        End If
        ' Close the connection and clear everything out
        ZIPCodes.Dispose()
        ZIPCodes = Nothing
        zcdDB.Dispose()
        zcdDB = Nothing


    End Sub

-------------------------------------------------

Then, on the page itself, I have the following:

<asp:Label ID="txtDealer" runat="server" Text="Label"></asp:Label> <asp:Label ID="txtCity" runat="server" Text="Label"></asp:Label>

-------------------------------------------------

Question, how do I make the results repeat?  In other words, it's only right now returning one record when there are multiple records in the database.  I want it to display the result, drop down a line, and then repeat it again until all the matching records are found.

I'm a bit new at this!

Thank you in advance,

Chris
0
Comment
Question by:jumpseatnews
23 Comments
 
LVL 9

Expert Comment

by:Chirag1211
ID: 19562972
Use a Repeater Control and place the Labels in the templates of Repeater Control.

for more details read the article on this link below:

http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatalist.aspx

Regards,

Chirag Patel
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19563152
Or other way around you can use datalist.

Following is the Html code I am putting of a small forum I developed.Where I used datalist


 <asp:DataList ID="DataList1" runat="server" CellPadding="4"  Width="100%"
            ForeColor="#333333" DataMember="DefaultView" RepeatColumns="1"  RepeatDirection="Horizontal" GridLines="Vertical" DataSourceID="SqlDataSource1"  >
           
            <SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#E3EAEB" />
            <ItemStyle BackColor="#E3EAEB" />
            <SeparatorStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                Font-Underline="False" ForeColor="Black" />
              <ItemTemplate>
                    <table width="100%" style="border-right: #cecece 1px solid; border-top: #cecece 1px solid; border-left: #cecece 1px solid; border-bottom: #cecece 1px solid;"  class="dtlst"  rules="cols" cellpadding="0" cellspacing="0">
                 <tr>
                     <td align="center" style="width: 100px">
                     <asp:Button ID="btnLink" runat="server" Text='<%# Eval("PostId") %>' BackColor="#E3EAEB" BorderStyle="None" Font-Underline="True"  />
                   
                        </td>
                     <td align="left" style="width: 700px; height:100px; text-align:left; margin-right:5px; vertical-align:top" >
                         <asp:Label ID="lblContent" runat="server" Text='<%# Eval("PostContent") %>' ></asp:Label></td>
                     <td align="center" style="width: 100px" >
                         <asp:Label ID="Label3" runat="server" Text='<%# Eval("PostOwner") %>'></asp:Label></td>
                     <td align="center" style="width: 100px" >
                         <asp:Label ID="Label4" runat="server" Text='<%# Eval("CreationDate") %>'></asp:Label></td>
                 </tr>
             </table>
                             &nbsp;
                             <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("AttachmentName") %>' OnClick="LinkButton1_Click"></asp:LinkButton>
                 
                </ItemTemplate>
         <HeaderTemplate>
             <table width="100%" style="border-right: #cecece 1px solid; border-top: #cecece 1px solid; border-left: #cecece 1px solid; border-bottom: #cecece 1px solid;"  class="dtls2"  rules="cols" cellpadding="0" cellspacing="0">    
                          <tr>
                     <td align="center" style="width: 99px">
                         Id</td>
                     <td align="center" style="width: 718px" >
                         Subject</td>
                     <td align="center" style="width: 97px" >
                         Owner</td>
                     <td align="center" style="width: 101px" >
                         Date</td>
                 </tr>
             </table>
         </HeaderTemplate>
         <EditItemTemplate>
             <br />
             <asp:TextBox ID="ids" runat="server" Text='<%# Eval("PostId") %>'></asp:TextBox>
             
         </EditItemTemplate>

        </asp:DataList>

Where ever you see Eval("xyz")

You can put column names of your data source.


Hope it helps
0
 

Author Comment

by:jumpseatnews
ID: 19565281
Hi,

Neither the repeater nor the datalist is working for me.  I'm getting an 'DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Dealer'. ' error message.

I tried using it this way:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ZIPCode As String = "92352"
        Dim Miles As Double = 500
        Dim DatabaseConnection As String
        Dim DatabaseQuery As String
        DatabaseConnection = ConfigurationManager.AppSettings("DataConnect")
        DatabaseQuery = "SELECT Latitude, Longitude FROM dbo.tblZipCodes WHERE ZIPCode = '" + ZIPCode + "'"

        Dim zcdDB As New SqlDataAdapter(DatabaseQuery, DatabaseConnection)
        Dim ZIPCodes As New DataSet()
        zcdDB.Fill(ZIPCodes, "ZIPCodes")

        Dim ZIPExists As Boolean = Not (ZIPCodes.Tables("ZIPCodes") Is Nothing)
        If ZIPExists Then
            Dim Latitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Latitude")
            Dim Longitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Longitude")
            Dim zcdRadius As New ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles)
            DatabaseQuery = "" _
                & "      SELECT * FROM vwDealerLocator WHERE" _
                & "            Latitude >= " & zcdRadius.MinLatitude _
                & "            AND Latitude <= " & zcdRadius.MaxLatitude _
                & "            AND Longitude >= " & zcdRadius.MinLongitude _
                & "            AND Longitude <= " & zcdRadius.MaxLongitude _
                & "            AND CityType = 'D'"

            zcdDB.SelectCommand.CommandText = DatabaseQuery
            zcdDB.Fill(ZIPCodes, "Radius")
            Dim zcdDistance As New ZIPCodeDownload.DistanceAssistant()
            Dim thisRow As System.Data.DataRow
            For Each thisRow In ZIPCodes.Tables("Radius").Rows
                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)
               
                ' Display the results
                If Distance <= Miles Then
                    Repeater1.DataSource = ZIPCodes
                    Repeater1.DataBind()
                End If
            Next
            ' Clear the variables
            zcdRadius = Nothing
            zcdDistance = Nothing
        End If
        ' Close the connection and clear everything out
        ZIPCodes.Dispose()
        ZIPCodes = Nothing
        zcdDB.Dispose()
        zcdDB = Nothing


    End Sub

--------------------------------

And on the page...

       <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" ><%#Eval("Dealer")%></asp:Label> <br />
        </ItemTemplate>
        </asp:Repeater>

--------------------------------

'Dealer' is a column in my vwDealerLocator table so I'm not sure why it is not showing up in the results and generating an object error.  However, when I use <%#Eval("Latitude")%> that seems to work ok.  But, I need access to all the other fields in the vwDealerLocator though and able to bind these columns to the repeater or datalist control.

I must apologize for this code, as it appears to be poorly written and not very well commented.  It came from this example: http://www.zipcodedownload.com/~Resources/SampleInfo/DLLDistRad.dotnet-vb.txt 

From this solution: http://www.zipcodedownload.com/Products/Product/DistRadAPI/Standard/ExampleCode/ 

Chris

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:chinu1310
ID: 19572341
Right because you are assigning zipcode to dealer.

Repeater1.DataSource = ZIPCodes

How is that gona take the value of dealer ?
0
 

Author Comment

by:jumpseatnews
ID: 19575277
Hi Chinu1310,

I'm not sure, as I thought that the 'ZIPCodes' dataset expressed in this code:
Dim ZIPCodes As New DataSet()
        zcdDB.Fill(ZIPCodes, "ZIPCodes")

...would contain all the values in the "SELECT * FROM vwDealerLocator WHERE..." query.

Essentially, all I'm trying to figure out how to do is:

1.) Perform a latitude/longitude lookup of the dbo.tblZipCodes and get the list of zip codes in that match.  (this is working fine in the earlier part of the code above).

2.) Perform a second query of the vwDealerLocator table where the records match the zip code.

3.) Display the results in a repeating fashion on the page, showing each dealer, address, phone, zip, etc.  (these are all columns in the vwDealerLocator table).  This would also need to be sorted by Miles, with shortest distance at the top of the results display.  'Miles' seems to be returned as a value called 'dist' from the ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles) function.

As I mentioned earlier, I'm kinda new at programming so I apologize if I didn't understand that the Repeater1.DataSource = ZIPCodes was incorrect.

Chris
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19579263
Ok.

Let me tell you this.
When you use datalist you are basically binding a dataset containing a datatable in it.

When you bind this dataset you make sure that what ever the  columns you are having in a dataset table,
there is a control say label to capture the value of it.

From your error as I said previously the problem is you mentioned a label with text property as
<%# Eval("Dealer") %> but your resulting dataset does not have this value at all.

So first make sure that you have all columns which you want to bind to the datalist.

Hope it helps.

0
 

Author Comment

by:jumpseatnews
ID: 19579434
There is a column called 'Dealer' in the vwDealerLocator table.  I don't understand why it is not displaying.
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19579445
Are you fetching that column which creates your final dataset which you bind to datalist.

If yes please put your entire aspx and .cs code here. Let me have a look where exactly the error is.
0
 

Author Comment

by:jumpseatnews
ID: 19579482
Thanks!  Here's the full code...

*** ON PAGE ***
<script runat="server">
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ZIPCode As String = "92352"
        Dim Miles As Double = 500
        Dim DatabaseConnection As String
        Dim DatabaseQuery As String
       
        ' Open connection and query tblZipCodes
        DatabaseConnection = ConfigurationManager.AppSettings("DataConnect")
        DatabaseQuery = "SELECT Latitude, Longitude FROM dbo.tblZipCodes WHERE ZIPCode = '" + ZIPCode + "'"

        Dim DataAdapter1 As New SqlDataAdapter(DatabaseQuery, DatabaseConnection)
        Dim ZIPCodes As New DataSet()
        DataAdapter1.Fill(ZIPCodes, "ZIPCodes")

        Dim ZIPExists As Boolean = Not (ZIPCodes.Tables("ZIPCodes") Is Nothing)
        If ZIPExists Then
            Dim Latitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Latitude")
            Dim Longitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Longitude")
            Dim zcdRadius As New ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles)
            DatabaseQuery = "SELECT * FROM vwDealerLocator WHERE" _
                & "            Latitude >= " & zcdRadius.MinLatitude _
                & "            AND Latitude <= " & zcdRadius.MaxLatitude _
                & "            AND Longitude >= " & zcdRadius.MinLongitude _
                & "            AND Longitude <= " & zcdRadius.MaxLongitude _
                & "            AND CityType = 'D'"

            DataAdapter1.SelectCommand.CommandText = DatabaseQuery
            DataAdapter1.Fill(ZIPCodes, "Radius")
            Dim zcdDistance As New ZIPCodeDownload.DistanceAssistant()
            Dim thisRow As System.Data.DataRow
            For Each thisRow In ZIPCodes.Tables("Radius").Rows
                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)

                If Distance <= Miles Then _
                    'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)
                Repeater1.DataSource = ZIPCodes
                Repeater1.DataBind()
            Next
            zcdRadius = Nothing
            zcdDistance = Nothing
        End If
        ZIPCodes.Dispose()
        ZIPCodes = Nothing
        DataAdapter1.Dispose()
        DataAdapter1 = Nothing


    End Sub
</script>



    <form id="form1" runat="server">
    <div><asp:Label ID="lblCity" runat="server" ></asp:Label>
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate><asp:Label ID="Label1" runat="server" ><%#Eval("Dealer")%></asp:Label> <br />
        <asp:Label ID="Label2" runat="server" ><%#Eval("City")%></asp:Label>
        <asp:Label ID="Label3" runat="server" ><%#Eval("Dist")%></asp:Label>
             <br />
        </ItemTemplate>
        </asp:Repeater>
</div>
    </form>

---------------------------------------

using System;

namespace ZIPCodeDownload {

      public class DistanceAssistant {

            private const int EARTH_RADIUS_MILES = 3963;

            public double Distance(double dblLat1, double dblLong1, double dblLat2, double dblLong2) {

                  //convert degrees to radians
                  dblLat1 = dblLat1 * Math.PI / 180;
                  dblLong1 = dblLong1 * Math.PI / 180;
                  dblLat2 = dblLat2 * Math.PI / 180;
                  dblLong2 = dblLong2 * Math.PI / 180;

                  double dist = 0;

                  if (dblLat1 != dblLat2 || dblLong1 != dblLong2) {
                        //the two points are not the same
                        dist =
                              Math.Sin(dblLat1) * Math.Sin(dblLat2)
                              + Math.Cos(dblLat1) * Math.Cos(dblLat2)
                              * Math.Cos(dblLong2 - dblLong1);

                        dist =
                              EARTH_RADIUS_MILES
                              * (-1 * Math.Atan(dist / Math.Sqrt(1 - dist * dist)) + Math.PI / 2);
                  }
                  return dist;
            }
      }
}


----------------------------------

Columns for Table vwDealerLocator: (merges two tables (tblZipCodes and tblDealerLocator)

ZipCode
Dealer
Address01
City
State
Zip
Phone
Website
Brand
Market
Speciality
Live
Latitude
Longitude
CityType




Schema for tblZipCodes:
ZIPCode
ZIPType
City
CityType
StateName
StateAbbr
AreaCode
Latitude
Longitude
0
 

Author Comment

by:jumpseatnews
ID: 19579497
Forgot to mention, here's the code they 'suggested' using.  Problem is, it doesn't display anything or repeat!

Dim _
    ZIPCode As String = "90210", _
    Miles As Double = 23.72, _
    DatabaseConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;User Id=;Password=;Data Source=C:\data.mdb", _
    DatabaseQuery As String = "SELECT Latitude, Longitude FROM ZIPCodes WHERE ZIPCode = '" + ZIPCode + "'"

Dim zcdDB As New System.Data.OleDb.OleDbDataAdapter(DatabaseQuery, DatabaseConnection)
Dim ZIPCodes As New System.Data.DataSet()
zcdDB.Fill(ZIPCodes, "ZIPCodes")

Dim ZIPExists As Boolean = Not (ZIPCodes.Tables("ZIPCodes") Is Nothing)
If ZIPExists Then
    Dim Latitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Latitude")
    Dim Longitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Longitude")
    Dim zcdRadius As New ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles)

    DatabaseQuery = "" _
        & "      SELECT * FROM ZIPCodes WHERE" _
        & "            Latitude >= " & zcdRadius.MinLatitude _
        & "            AND Latitude <= " & zcdRadius.MaxLatitude _
        & "            AND Longitude >= " & zcdRadius.MinLongitude _
        & "            AND Longitude <= " & zcdRadius.MaxLongitude _
        & "            AND CityType = 'D'"

    zcdDB.SelectCommand.CommandText = DatabaseQuery
    zcdDB.Fill(ZIPCodes, "Radius")
    Dim zcdDistance As New ZIPCodeDownload.DistanceAssistant()
    Dim thisRow As System.Data.DataRow
    For Each thisRow In ZIPCodes.Tables("Radius").Rows
        Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
        Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
        Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)

        If Distance <= Miles Then _
            Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)

    Next
    zcdRadius = Nothing
    zcdDistance = Nothing
End If
ZIPCodes.Dispose()
ZIPCodes = Nothing
zcdDB.Dispose()
zcdDB = Nothing
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19579503
Ok got the problem.

See this code.
For Each thisRow In ZIPCodes.Tables("Radius").Rows
                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)

                If Distance <= Miles Then _
                    'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)
                Repeater1.DataSource = ZIPCodes
                Repeater1.DataBind()
            Next

Here what you are trying to do is if the radius<miles satisfies than you are binding it to datalist.
Right ?

But datalist doesn't work that way. First find all the dealers who are within the radius make dataset of them and finally bind that dataset.

Datalist can not skip the according to your loop it binds all the columns in your dataset to itself.
0
 

Author Comment

by:jumpseatnews
ID: 19579539
OK, so then if I remove the if distance..., and bind to zipcodes it will work?

I tried this:

<script runat="server">
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ZIPCode As String = "92352"
        Dim Miles As Double = 500
        Dim DatabaseConnection As String
        Dim DatabaseQuery As String
       
        ' Open connection and query tblZipCodes
        DatabaseConnection = ConfigurationManager.AppSettings("DataConnect")
        DatabaseQuery = "SELECT Latitude, Longitude FROM dbo.tblZipCodes WHERE ZIPCode = '" + ZIPCode + "'"

        Dim DataAdapter1 As New SqlDataAdapter(DatabaseQuery, DatabaseConnection)
        Dim ZIPCodes As New DataSet()
        DataAdapter1.Fill(ZIPCodes, "ZIPCodes")

        Dim ZIPExists As Boolean = Not (ZIPCodes.Tables("ZIPCodes") Is Nothing)
        If ZIPExists Then
            Dim Latitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Latitude")
            Dim Longitude As Double = ZIPCodes.Tables("ZIPCodes").Rows(0)("Longitude")
            Dim zcdRadius As New ZIPCodeDownload.RadiusAssistant(Latitude, Longitude, Miles)
            DatabaseQuery = "SELECT * FROM vwDealerLocator WHERE" _
                & "            Latitude >= " & zcdRadius.MinLatitude _
                & "            AND Latitude <= " & zcdRadius.MaxLatitude _
                & "            AND Longitude >= " & zcdRadius.MinLongitude _
                & "            AND Longitude <= " & zcdRadius.MaxLongitude _
                & "            AND CityType = 'D'"

            DataAdapter1.SelectCommand.CommandText = DatabaseQuery
            DataAdapter1.Fill(ZIPCodes, "Radius")
            Dim zcdDistance As New ZIPCodeDownload.DistanceAssistant()
            Dim thisRow As System.Data.DataRow
            For Each thisRow In ZIPCodes.Tables("Radius").Rows


                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)
                'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)
                Repeater1.DataSource = ZIPCodes
                Repeater1.DataBind()
                zcdRadius = Nothing
                zcdDistance = Nothing
            Next
            ZIPCodes.Dispose()
            ZIPCodes = Nothing
            DataAdapter1.Dispose()
            DataAdapter1 = Nothing
        End If

    End Sub
</script>

but I got this error message:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Dealer'.
Line 67:         <ItemTemplate><asp:Label ID="Label1" runat="server" ><%#Eval("Dealer")%></asp:Label> <br />
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19579601
For Each thisRow In ZIPCodes.Tables("Radius").Rows


                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)
                'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)
                Repeater1.DataSource = ZIPCodes
                Repeater1.DataBind()
                zcdRadius = Nothing
                zcdDistance = Nothing
            Next

See it will not solve your problem.
You can not bind datasource more than one time.
-----------------

Once you get list you make this loop as it is but this way. I am writing some pseudo code

For Each thisRow In ZIPCodes.Tables("Radius").Rows


                Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
                Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
                Dim Distance As Double = zcdDistance.Distance(Latitude, Longitude, Latitude2, Longitude2)
                'Console.WriteLine("City (Distance) = {0} ({1})", thisRow("City"), Distance)
               
              //Create new datatable
             //Create row and columns in that datatable
            //if the current item in your dataset satisfies radius<miles add that row to newly created table.

           

//Repeater1.DataSource = ZIPCodes
                //Repeater1.DataBind()
                zcdRadius = Nothing
                zcdDistance = Nothing
            Next

  //At the end of loop add this table to your dataset.say zipcodes
           //And than bind that newly created table to the datalist.

Hope you get this correct.

-----------------

One more thing is there a way you can create some kind of stored procedure which will result directly the list of dealers with radius<miles.

Of course that is a second part but first do what I suggested before in this post.
0
 

Author Comment

by:jumpseatnews
ID: 19579762
I'm afraid I don't understand how to do this.  I'll look for some articles on this I guess and see if I can figure out what you are trying to say is the solution.
0
 

Author Comment

by:jumpseatnews
ID: 19579770
Essentially, I'm trying to do this in ASP.NET.

This is classic ASP, but allow a simple recordset to be created and also query works well and fails in .NET



<%

Else
    'ZIP Code does exist...get lat/long
    Latitude = rsZIPCodes("Latitude")
    Longitude = rsZIPCodes("Longitude")
    ZIPExists = True
End If
rsZIPCodes.Close
Set rsZIPCodes = Nothing

'2. Find the lines of latitude & longitude to the north, south, east and west of requested Zip Code

If ZIPExists Then
    Dim zcdRadius: Set zcdRadius = new RadiusAssistant
    zcdRadius.Calculate Latitude, Longitude, Miles
    Dim MaxLatitude, MaxLongitude, MinLatitude, MinLongitude
    MaxLongitude = zcdRadius.MaxLongitude
    MinLongitude = zcdRadius.MinLongitude
    MaxLatitude = zcdRadius.MaxLatitude
    MinLatitude = zcdRadius.MinLatitude
    Set zcdRadius = Nothing

' 3. Perform a database query which returns all records with the lines of lat/long to each side of requested Zip Code
   
DatabaseQuery = "" &_
        "SELECT * , acos(sin((" & Latitude & " * 3.14159265358979323846 / 180)) * sin((Latitude * 3.14159265358979323846 / 180)) " + cos((" & Latitude &" * 3.14159265358979323846 / 180)) * cos((Latitude * 3.14159265358979323846 / 180)) * cos((("Longitude & " - Longitude) * 3.14159265358979323846 / 180))) * 180 / 3.14159265358979323846 * 60 * 1.1515 " AS Dist " &_
          "FROM vwDealerLocator WHERE" &_
          "Latitude >= " & MinLatitude &_
          "AND Latitude <=" & MaxLatitude &_
          "AND Longitude >= " & MinLongitude &_
          "AND Longitude <= " & MaxLongitude &_
          "ORDER BY Dist ASC, account ASC"
            

    Set rsZIPCodes = CreateObject("ADODB.Recordset")
    rsZIPCodes.Open DatabaseQuery, dbConn
      %>
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19579858
See that is the interesting part. The query you presented last will directly result the set  of all the dealers who have radius<distanc. If you can run the same query in the asp .net than just bind this result set to data list. And you are done.
0
 

Author Comment

by:jumpseatnews
ID: 19579871
Yes, that's exactly what i would like to do.  I just do not know how to make that conversion to ASP.net and bind to a repeater control.

0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19584115
Give me some time. Let's see how much I have on this weekend. Than I will do that code for you.
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19625423
Any luck uptill now ?
0
 

Author Comment

by:jumpseatnews
ID: 19626658
Hi Chinu1310:

Not yet.  I've got it working in an .asp environment, but still no luck yet on .NET.  I"m looking into the datareader now so if I found something I'll post here.

Thanks for checking,

Chris
0
 
LVL 1

Accepted Solution

by:
Devsolutions earned 2000 total points
ID: 19709229
I had similar error coming up while i was using detailview with gridview and my error was
'System.Data.DataRowView' does not contain a property with the name 'TemplateId'

I was passing templateId as input parameter to the stored procedure,However i was not selecting templateId deom teh select query.
I just did select TemplateId,name from template where templateId = @templateId

and my problem got solved.
The similar problem was coming with difft module earlier as well and was solved in the same way.
I just try checking the sql query and detailsview templates...

BEST OF LUCK
Devsolutions

0
 

Author Comment

by:jumpseatnews
ID: 19730614
Hi Devsolutions,

I'll check this out also.  Thanks for the heads up on that error/solution.

Chris
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20432477
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question