Majid Basirati
Majid Basirati

Reputation: 2865

Change the SqlDataSource SelectCommand

I have a SqlDataSource for a gridview. I want to change SelectCommand of that SqlDataSource.

My select command is:

select *   
from JobLog 
where UserName = @username 
  and PrinterName = @printer 
  and TimeSubmitted between @from and @to

I want to replace @username and ... with textboxes.

How can I do this?

Upvotes: 0

Views: 359

Answers (1)

CM Kanode
CM Kanode

Reputation: 1436

In your SQLDataSource, add SqlParameter to it. Add one for each textbox that you want to use for the query. Example:

<SelectParameters>
    <asp:ControlParameter Name="UserName" ControlID="txtUserName" />
</SelectParameters>

Upvotes: 1

Related Questions