In my ASP.net application I have an SqlDataSource
with parameters e. g.:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..."
onselecting="SqlDataSource1_Selecting" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT * FROM [SomeTable] WHERE ([SomeTableID] = @SomeTableID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="SomeTableID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
For debugging purposes it would be very helpful to somehow catch the query string which is executed on the database server i. e. the query string with filled in parameter values.
I tried to do this in the SqlDataSource1_Selecting
event, but the SqlDataSourceSelectingEventArgs
arguments still contain the SelectCommand
text as above: SELECT * FROM [SomeTable] WHERE ([SomeTableID] = @SomeTableID)
.
How can I get the true query string with all @Valiables replaced by the values which are used for the selection?
SelectCommand.Parameters
? – Tim Aug 8 '13 at 6:28SelectCommand.Parameters
and I could get the values one by one there. But if you have a very long query with many parameters this is quite annoying. – Rob Aug 8 '13 at 6:34