[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

help with using parameter in query string. asp.net, c#

I found an example of how to do an SQL query that I really liked. It's nice and clean so I figured I would change what I normally do. But now I don't know how to use the parameter correctly using this style of code.

Basically, it's a master/detail situation. I have a query string being passed and it has the right value. What I want is a select statement that will pull the details where the AccountID =AAMPRA0016A - just like what the string being passed says. So that part seems to be fine.

My query string from the preceding page looks like this:
http://localhost:30559/Portal/oppDetail.aspx?ACCOUNT.ACCOUNTID=AAMPRA0016AQ

Open in new window


And the select statement I have on the details page looks like this:
SqlDataSource SqlDataSource1 = new SqlDataSource();
                    SqlDataSource1.ID = "SqlDataSource1";
                    this.Page.Controls.Add(SqlDataSource1);
                    SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["qConnectionString"].ConnectionString;
                    SqlDataSource1.SelectCommand = "SELECT OPPORTUNITY.DESCRIPTION, OPPORTUNITY.SALESPOTENTIAL, OPPORTUNITY.STAGE, OPPORTUNITY.REGISTERED FROM ACCOUNT INNER JOIN OPPORTUNITY ON ACCOUNT.ACCOUNTID = OPPORTUNITY.ACCOUNTID WHERE (ACCOUNT.ACCOUNTID = ?)";
                    SqlDataSource1.SelectParameters.Equals("@ACCOUNT.ACCOUNTID");
                    DetailsView1.DataSource = SqlDataSource1;
                    DetailsView1.DataBind();

Open in new window


I'd appreciate some help making this work.

Thanks,
mh
0
MHenry
Asked:
MHenry
1 Solution
 
Robert SchuttSoftware EngineerCommented:
Please try this:

in the select statement on line 5, replace ? with @ACCOUNTID

replace line 6 with:
SqlDataSource1.SelectParameters.Add(new QueryStringParameter("ACCOUNTID", System.Data.DbType.String, "ACCOUNT.ACCOUNTID"));

Open in new window

0
 
MHenryAuthor Commented:
Awesome, thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now