With VS2005, there is a new component SqlDataSource,
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
Then you can assign SP and bind datasource to a get data for this component in .NET code:
SqlDataSource1.SelectCommand = "spName"
SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
SqlDataSource1.ConnectionString = Comm.connString
There is no way to set sqlcommand timeout for this stored procedure like SqlClient.SqlCommand. How can I do this?
Inside the SqlDataSource1_Selecting event, you get access to the sqlcommand object via e.command. You can set the commandtimeout on it there, like:
e.Command.CommandTimeout=300
||| Thanks for your reply. But when is the event Selecting fired? Is it fired automatically when binding to data source?
Hi KentZhou,
The sqldatasource.selecting event happends right before your perform a data retrieval opteration(where you execute your select command).You can refer to the msdn explaination:
msdn:
Occurs before a data retrieval operation.
Handle theSelecting event to perform additional initialization operations that are specific to your application, to validate the values of parameters, or to change the parameter values before theSqlDataSource control performs the select operation. The select arguments are available from theSqlDataSourceSelectingEventArgs object that is associated with the event.
Hope my suggestion helps
|||The short answer is "Yes".
It fires any time that you do a databind.
The long answer as described above, it actually happens any time that the SqlDatasource is about to go and execute your select command. This is normally done through a databinding operation (Either implied or programmatically triggered), however it can also be triggered if you call the select method on the SqlDatasource directly.
No comments:
Post a Comment