Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Listing Stores Under Certain Areas
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Listing Stores Under Certain Areas

 Post Reply Post Reply Page  <123
Author
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 20 October 2004 at 2:51pm
Sorry man but it almost appears your db has a problem, if you set ds.Tables("Area") as your parent Relation and get an error that the columns currently don't have unique values, it means there is AreaID more then once. Or you did a Select * again which may pull the wrong Area in duplicates. Why don't you just post the code you have at this point. I mean I did that 1000 times and always worked so I am sure it is something very simple we are overlooking. If you could also write out both datasets into an xml file with ds.WriteXML("c:...") so I have your data to play with. I will PM you my email addy if you want to mail the xml to me
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 02 November 2004 at 3:19pm

I finally solved this problem by changing this sql statement to:

Dim mySQL2 as string  = "Select Area.AreaID, AreaName from Area Inner Join SpaStore ON Area.AreaID = SpaStore.AreaID where Area.State = '" & strChosenState & "' AND ListingType IN ('Featured','National') AND Approve = 1 Group By Area.AreaID, AreaName Order by AreaName"

I had to group by Area.AreaID for it to work.

Here's my code in case anyone needs to create a complicated nested datalist like this in the future:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Page Language="VB" Debug="true" %>
<html>
<head>

 <title>Nested DataLists</title>
<script language="VB" runat="server">

'----------------------------------------------------------- ------
' name: FieldValueIsMissing(objValueToCheck As Object) As Boolean
'----------------------------------------------------------- ------
Function FieldValueIsMissing(objValueToCheck As Object) As Boolean

        if objValueToCheck is DBNull.Value Then
                 return True
        else
                 return False
        end if


End Function

Sub Page_Load(Source as Object, E as EventArgs)
 Dim strConn as string = "server=servername;uid=username;pwd=password;database=databa sename"
 Dim strChosenState as String
 
 'Get incoming querystring values
    strChosenState = request.params("State")
 
 Dim MySQL as string = "Select * from SpaStore INNER JOIN Area ON SpaStore.AreaID = Area.AreaID where Area.State = '" & strChosenState & "' AND ListingType IN ('Featured','National') AND Approve = 1 ORDER by SpaStoreName"
 Dim MyConn as New SQLConnection(strConn)
 Dim ds as DataSet=New DataSet()
 
 Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
 Cmd.Fill(ds,"SpaStore")
   
   
    Dim mySQL2 as string  = "Select Area.AreaID, AreaName from Area Inner Join SpaStore ON Area.AreaID = SpaStore.AreaID where Area.State = '" & strChosenState & "' AND ListingType IN ('Featured','National') AND Approve = 1 Group By Area.AreaID, AreaName Order by AreaName"


    Dim cmd2 As SqlDataAdapter = New SqlDataAdapter(MySQL2,MyConn)
    cmd2.Fill(ds, "Area")

    ds.Relations.Add("myrelation", ds.Tables("Area").Columns("AreaID"), ds.Tables("SpaStore").Columns("AreaID"))

 dlArea.Datasource=ds.Tables("Area").DefaultView
 DataBind()
End Sub

</script>
</head>
<body>
<asp:DataList runat="server"
 Id="dlArea">
 
 <HeaderTemplate>
  
 </HeaderTemplate>
 <ItemTemplate><table><tr><td>& lt;font color="red" font size=4><%# Container.DataItem("AreaName")%>
  </font></td></tr></table> ; <p>
   <asp:DataList runat="server"
    Id="ChildDataList"
    GridLines="None"
    Bordercolor="black"
    cellpadding="3"
    cellspacing="0"
    Headerstyle-BackColor="#8080C0"
    Headerstyle-Font-Name="Arial"
    Headerstyle-Font-Size="8"
    Font-Name="Arial"
    Font-Size="8"
    datasource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'
    RepeatColumns="3">
    <ItemTemplate><p><p&g t;<table>
    <tr><td> <%# Container.DataItem("SpaStoreName")%>
    </td></tr>
    <tr><td><%# Container.DataItem("Address") %></td></tr>
                 <tr><td><%# Container.DataItem("City") %>, <%# Container.DataItem("State")%> <%# Container.DataItem("Zip") %> </td></tr>
    <p></p>
    </ItemTemplate>
   </ASP:DataList>
 </ItemTemplate>
</ASP:DataList>
</table>
</body>
</html>

 

Back to Top
 Post Reply Post Reply Page  <123

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.