1myb
1myb

Reputation: 3596

Code behind in aspx sql

May I know how could I pass the value of driver from code behind and throw into the query in aspx file ?

Here is my aspx part:

<asp:SqlDataSource ID="cs_sc" runat="server" 
ConnectionString="<%$ ConnectionStrings:MIMConnectionString %>"
SelectCommand="SELECT * FROM [Cash_Sales] WHERE [driver] = @driver">
<SelectParameters>
    <asp:Parameter Name="driver" Direction="Input" Type="String" />
</SelectParameters></asp:SqlDataSource>

code behind:

protected void Button1_Click(object sender, EventArgs e)
{
    driver = driverUpdateBox.SelectedItem.Text;
}

Upvotes: 0

Views: 550

Answers (3)

Antonio Bakula
Antonio Bakula

Reputation: 20693

SqlDataSource has SelectParameters property, use it like this :

protected void Button1_Click(object sender, EventArgs e)
{
  cs_sc.SelectParameters["driver"] = driverUpdateBox.SelectedItem.Text;
}

Upvotes: 1

Rab
Rab

Reputation: 35582

cs_sc.SelectParameters["driver"].DefaultValue = driverUpdateBox.SelectedItem.Text;

Upvotes: 3

Jupaol
Jupaol

Reputation: 21365

Have you tried something like this:

SelectCommand="SELECT * FROM [Cash_Sales] WHERE [driver] = <%$ this.driver %>">

Upvotes: 1

Related Questions