Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable from URL to SQL statement in ASP

Status
Not open for further replies.

mtepfer

IS-IT--Management
Apr 21, 2003
55
US
This is my first time trying to write something in ASP.net so please bear with me if I don't explain it correctly.

I created a view in SQL and attached it to a sql data source in my ASP page and displayed it using a data list.

I ran the page and the information comes back no problem with the correct data. The statement looked like this :

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:yardi_reportConnectionString %>"
SelectCommand="SELECT * FROM PH_UnitStats] "></asp:SqlDataSource>

So the goal was to attach the page as a webpart in Sharepoint. Within Sharepoint we have several properties. So based on the property selected the url when then pass the property code to the asp page to query only that recordset where propid = ?

So my statement in the asp page looks like this now :
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:yardi_reportConnectionString %>"
SelectCommand="SELECT * FROM [PH_UnitStats] where p.hmy = 'iddetail'"></asp:SqlDataSource>

where p.hmy is the column in the property table

where the declaration above is :

Dim iddetail
iddetail = Request.QueryString("propid")

Now that I have added this and try to run it I am getting the following error:

SqlException (0x80131904): The column prefix 'p' does not match with a table name or alias name used in the query.]

Any help or guidance is greatly appreciated


 
Thanks Sirius, but after further research found it was my view, i was doing a straight count(*) but hadn't added the hmy field into the select statement. So added that into the select statement then also added a group by and now that error is gone. Am getting a different error dealing with data type but nothing to do with this issue.

Thanks for the prompt reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top