Showing posts with label inner. Show all posts
Showing posts with label inner. Show all posts

Wednesday, March 7, 2012

Please Please Help with C# and ASP.net

I am trying to do an inner join on two tables with the following look
Table Name: Event
Event.event_id (primary key)
Event.venue_id
Event.artist_id
Event.date_time
Table Name: Venue
Venue.venue_id
Venue.name
Venue.city
Venue.state
I want to be able to display them but i get an error with the following code
SqlConnection conn = new SqlConnection(connect_string);
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataSet ds = new DataSet();
adp.Fill(ds,"Event"); //Error below falls on this line of code.
foreach (DataRow dr in ds.Tables["Event"].Rows)
{
date_label.Text += dr["Event.date_time"].ToString()+ "<br>";
}
How do i do this join and be able to output the information of the Event.date_time, Venue.city, Venue.name, Venue.state
I get the following error

The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query.


(1) It would look like"
SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event INNER JOIN Venue ON Event.venue_id=Venue.venue_id WHERE Event.artist_id=@.artId ORDER BY Event.date_timeASC";
(2) Notice I have used @.artId.You should be using parameterized queriesto prevent SQL Injection attack ( a simple google search on this willgive you enough information).
|||Your string:
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
Should be:
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state "
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
(I added a space at the end of the first line. The "Venue.state" and "FROM" were concatenated)
|||Thanks for pointing that out scampbell12001.

Monday, February 20, 2012

Please help, my query is hanging the server and preventing others from updating the table

Hi,
I'm having a big problem.,
if I issue the following query:
SELECT Customers.*, Employees.*
FROM Customers INNER JOIN
Employees ON Customers.EmployeeID =
Employees.EmployeeID
Then while this query is running all other users are unable to make any
Updates to the Customer Table. If I remove the join and only query the
customer table then other users are able to update the customer table
while this query is running.. The problem is that I need to do a join
so that I can pull some data from the employee table that corresponds to
data within the customer table. Is there a way around this?
Thanks,
In addition to Tibor's advise, do not use '*' in production . Do you realy
need all columns from both tables?
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:eGCLi0FdIHA.4144@.TK2MSFTNGP05.phx.gbl...
> Do you have indexes to support the join? I.e. an index on
> Customers.EmployeeID and one on Employees.EmployeeID.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "RobDob" <jsmith20042005@.yahoo.com> wrote in message
> news:16689F4712774D569058EC91B8FDC70B@.rkstriglPC.. .
>
|||"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eJO0caHdIHA.4712@.TK2MSFTNGP04.phx.gbl...
> In addition to Tibor's advise, do not use '*' in production . Do you
> realy need all columns from both tables?
>
And to add what Uri asked, do you really need to return ALL rows?

>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
> in message news:eGCLi0FdIHA.4144@.TK2MSFTNGP05.phx.gbl...
>
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html