edward
edward

Reputation: 53

asp.net sql selecting data from multiple tables

[IMG]http://i62.tinypic.com/2141deb.jpg[/IMG]

The image above is my 3 tables i have created and filled up with my data. I am using Visual Studio 2013, though i think with my question all details are irrelevant as it is a basic sql problem.

< <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:ConnectPizza %>" 
SelectCommand="SELECT users.[title], users.[gname], users.[sname], users.[suburb], users.[postcode], pizzas.[type], orders.[pizza-size] orders.[quantity] 
FROM orders JOIN users ON users.[username]=orders.[username] JOIN pizzas ON pizzas.[pizza-id] = orders.[id]">
 <SelectParameters>
 <asp:SessionParameter SessionField="login_username"
 Name="username" />
 </SelectParameters>
 </asp:SqlDataSource>

When i do this code i get a basic syntax error "Incorrect syntax near '.'. " What am i doin wrong, i know since there is a hyphen in one of my column names pizza-id I decided to put braces around all of them. Any help would be grateful

Upvotes: 0

Views: 613

Answers (1)

Edi G.
Edi G.

Reputation: 2422

you frogot a comma in:

SELECT users.[title], users.[gname], users.[sname], users.[suburb], users.[postcode], pizzas.[type], orders.[pizza-size] orders.[quantity] 

between orders.[pizza-size] and orders.[quantity]

    SELECT u.title, u.gname, u.sname, u.suburb, u.postcode, p.type, o.pizza-size, o.quantity 
      FROM orders o 
INNER JOIN users u ON u.username=o.username 
INNER JOIN pizzas p ON p.pizza-id = o.id 

and remove the []

Upvotes: 1

Related Questions