naijacoder
naijacoder

Reputation: 464

Passing Parameters for SqlDataSource from code behind

whats the diffrence btw this two SqlDataSource1?

<SelectParameters>
                <asp:Parameter Name="user"  />

</SelectParameters>

SqlDataSource1.SelectParameters("user").DefaultValue = "some value";

SqlDataSource1.SelectParameters("@param",user);

When i use

SqlDataSource1.SelectParameters("user").DefaultValue = "some value";

it works but SqlDataSource1.SelectParameters("@param",user); doesn't:

Upvotes: 2

Views: 10701

Answers (2)

Mubarek
Mubarek

Reputation: 2689

In the selecting event of the SqlDataSource control pass the value to the to the parameter:

 protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
  {
   e.Command.Parameters["@user"].Value="value";
  }

Upvotes: 3

Dana Addler
Dana Addler

Reputation: 983

I think you should use smth. like this:
SqlDataSource1.SelectParameters.Add("@param",user);

that has some overloads.

Upvotes: 0

Related Questions