Michael,
Let me give you the code that I have. I still want to use the following sql statement: strSQL = "Select * From SpaStore, Area"
strSQL = strSQL & " where SpaStore.Area = Area.AreaID"
strSQL = strSQL & " and Area.State = '" & strChosenState & "'"
strSQL= strSQL & " and ListingType IN ('Featured','National')"
strSQL = strSQL & " and Approve=0"
strSQL = strSQL & " Order By SpaStoreName"
Here's my code:
Sub Page_Load(Source as Object, E as EventArgs)
Dim strConn as string = My connection details
Dim strChosenState as String
'Get incoming querystring values
strChosenState = request.params("State")
Dim MySQL as string = "Select * from Area where State = '" & strChosenState & "'" - this would work when I just had select * from Area" But I must have this and everything else in the sql statement that I have to get the results that I need. I got the following error message:
This constraint cannot be enabled as not all values have corresponding parent values when I added that particular where statement.
Dim MyConn as New SQLConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"Area")
Dim cmd2 As SqlDataAdapter = New SqlDataAdapter("select * from SpaStore where ListingType IN ('Featured','National') and Approve=0 Order By SpaStoreName", MyConn)
cmd2.Fill(ds, "SpaStore") - I tested this. It worked when I took the where statement away from the first sql statement above.
ds.Relations.Add("myrelation", ds.Tables("Area").Columns("AreaID"), ds.Tables("SpaStore").Columns("Area"))
dlArea.Datasource=ds.Tables("Area").DefaultView
DataBind()
End Sub
</script>
</head>
<body>
<asp:DataList runat="server"
Id="dlArea">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate><table><tr><td>& amp; amp; amp; 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&a mp;a mp;a mp;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>
Edited by Misty