Rumpelstinsk
Rumpelstinsk

Reputation: 3241

SqlDatasource: Parameters on Select()

After reading https://msdn.microsoft.com/es-es/library/system.web.ui.webcontrols.sqldatasource.select(v=vs.110).aspx

I'm a bit confused about the Select() method of the SqlDatasource. It's easy to explain with an example. Let's consider this test code:

//sql is a SqlDatasource, let's get out the question the initialization.
sql.SelectCommand= "select * from employees where iddepartment = @iddeparment";
sql.SelectParameters.Add("iddepartment ", DbType.Int, "1");

At this point, I need to retrieve the data, so i try to do something like:

IEnumerable<object> myData = sql.Select();

However according to MSDN documentation, Select methods requieres 1 parameter of type DataSourceSelectArguments. This confuses me, Why do I have to pass some "Select parameters" as an argument if I already set them by calling SelectParameter.Add(...)? How can I call correctly this function?

Upvotes: 2

Views: 1517

Answers (1)

jegtugado
jegtugado

Reputation: 5141

DataSourceSelectArguments is not what you thought it is. For your case, you can simply pass DataSourceSelectArguments.Empty.

Data-bound controls use the DataSourceSelectArguments class to request that a data source control performs additional data-related operations on a result set, such as sorting the data or returning a specific subset of data. These data-related operations are enumerated by the DataSourceCapabilities enumeration. The following table indicates how the DataSourceSelectArguments class supports these data-related operations.

This parameter can contain information regarding the filters to apply or the column to Order By. For example, when working with a sortable GridView, sorting a column calls the Select() method, and passes in a DataSourceSelectArguments instance with its SortExpression property set to the column name the user chose to sort by. If you don't want the DataSource to sort or filter, you pass in DataSourceSelectArguments.Empty.

Upvotes: 3

Related Questions