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
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: 19 October 2004 at 6:08pm

Michael,

I think I am almost there. But I am getting the following error message:

These columns don't currently have unique values.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: These columns don't currently have unique values.

Source Error:

Line 25:    	cmd2.Fill(ds, "Area")
Line 26: 
Line 27:    	ds.Relations.Add("myrelation", ds.Tables("Area").Columns("AreaID"), ds.Tables("SpaStore").Columns("AreaID"))
Line 28: 
Line 29: 	dlArea.Datasource=ds.Tables("Area").DefaultView

Here's my second sql statement:

    Dim mySQL2 as string  = "Select * from Area INNER JOIN SpaStore ON Area.AreaID = SpaStore.AreaID where Area.State = '" & strChosenState & "' AND ListingType IN ('Featured','National') AND Approve = 0 ORDER by AreaName"
    Dim cmd2 As SqlDataAdapter = New SqlDataAdapter(MySQL2,MyConn)
    cmd2.Fill(ds, "Area")

I am puzzled why it won't work. It will work when I just have mySQL2 = "Select * from Area where State = '" & strChosenState "'", it will work. But I get all of the areas for that states even if there are no spa stores under that area. Do you have any idea on how I can fix this problem? Thank You!

Back to Top
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: 19 October 2004 at 6:19pm
First off, don't do a Select *, that is bad practice, just select the fields for table area you need...
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: 19 October 2004 at 7:07pm

When I selected  AreaName from the above sql statement, it said something about not being able to accept null values. I will only get this error message if there is more than one store under one area. The error message says: These columns don't currently have unique values. This is puzzling. It still would not work when I remove the primary key from the AreaID in Area table. I must have a typo. It could be because the Area table is the master table. Does anyone have any ideas on how to fix this problem?

Look at the below code that is causing the problem:

Dim mySQL2 as string  = "Select * from Area where Area.State = '" & strChosenState & "' 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"))

 



Edited by Misty
Back to Top
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: 19 October 2004 at 11:09pm

OK, I did not look through all the source we have been playing around with.
The below pseudo code works


Dim MySQL As String = "Select AreaID, Area from Area where State = '" & strChosenState & "'"

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 Join Area ON SpaStore.AreaID = Area.AreaID where State = '" & strChosenState & "'", MyConn)

cmd2.Fill(ds, "SpaStore")

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

dlArea.DataSource = ds.Tables("Area").DefaultView

DataBind()

The problem you had that the parent row does not have corresponding parent values is because you chose SpaStore that are in the strChosenAreaID but you chose ALL Areas, that will cause a conflict, you need to set the same filter on the spaStore table. I put above code in a page and verified it does work well.

Back to Top
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: 19 October 2004 at 11:10pm
Forgot to mention, you changed a few column names like AreaName to Area or so. Make sure you reflect that...
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: 20 October 2004 at 1:07am

AreaName is actually right. I accidentally called the AreaID in the SpaStore Table Area at one time which was not a good idea.

Let me tell you some information about my tables that are relevant:

Area: AreaID, AreaName, State
SpaStore: SpaStoreID, SpaStoreName, AreaID, State, Approve, ListingType, etc.

I used the above code that you gave me. I had to modify it a little because State in the second SQL Statement had to be SpaStore.State. I didn't get any error messages. But I am getting all of the areas even if there are no stores under a certain area. I only want areas that have stores under them to be displayed. I've tried some experiments by changing some of the code, but I have been unsuccessful.

Here's my code:

Dim MySQL As String = "Select AreaID, AreaName from Area where State = '" & strChosenState & "' Order By AreaName" - I think that we need to modify this sql statement. This sql statement chooses all of the areas that are under a certain state. For example, (GA) Georgia might have the following areas: Atlanta Area, Middle Georgia, South Georgia, and Northeast Georgia. All of the areas would be displayed with this sql statement. Let's say that I only have one store under North Georgia and three stores under Atlanta Area. I would like for only North Georgia and Atlanta Area to be displayed as areas on the web page.

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 Join Area ON SpaStore.AreaID = Area.AreaID where Area.State = '" & strChosenState & "' AND ListingType IN ('Featured','National') AND Approve = 0 ORDER by SpaStoreName", MyConn)

cmd2.Fill(ds, "SpaStore")

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

dlArea.DataSource = ds.Tables("Area").DefaultView

DataBind()
 

Back to Top
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 9:49am
To only get the Areas that have SpaStores you need to do a join on the SpaStore Table like I posted some time ago, I had just simplified it above.

Dim MySQL As String = "Select Area.AreaID, Area.Area from Area Join SpaStore ON Area.AreaID = SpaStore.AreaID where Area.State = '" & strChosenState & "'"

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: 20 October 2004 at 2:43pm
I did what a join on the Area table. I tried this before. I tried the code that you posted again. It didn't work. I got the following error message: Exception Details: System.ArgumentException: These columns don't currently have unique values.

Source Error:

Line 43:    	cmd2.Fill(ds, "Area")
Line 44: 
Line 45:    	ds.Relations.Add("myrelation", ds.Tables("Area").Columns("AreaID"), ds.Tables("SpaStore").Columns("AreaID"))
Line 46: 
Line 47: 	dlArea.Datasource=ds.Tables("Area").DefaultView
again. There may be a typo somewhere that we both didn't notice. Are there any other ideas on how to work around this problem?
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.