1

I need to debug some code involving SqlDataSource SelectParameters, and I would like to get the value of these parameters, but so far I'm only able to get the name of the parameters.

Dim debug As String = "Parameter 1: " & SqlDataSource1.SelectParameters.Item(0).ToString() & "<br />" & _
        "Parameter 2: " & SqlDataSource1.SelectParameters.Item(1).ToString() & "<br />" & _
        "Parameter 3: " & SqlDataSource1.SelectParameters.Item(2).ToString() & "<br />" & _
        "Parameter 4: " & SqlDataSource1.SelectParameters.Item(3).ToString() & "<br />" & _
        "Parameter 5: " & SqlDataSource1.SelectParameters.Item(4).ToString() & "<br />" & _
        "Parameter 6: " & SqlDataSource1.SelectParameters.Item(5).ToString() & "<br />" & _
        "Parameter 7: " & SqlDataSource1.SelectParameters.Item(6).ToString() & "<br />" & _
        "Parameter 8: " & SqlDataSource1.SelectParameters.Item(7).ToString() & "<br />" & _
        "Parameter 9: " & SqlDataSource1.SelectParameters.Item(8).ToString() & "<br />"

    Label3.Text = debug

Output:

Parameter 1: institution
Parameter 2: type
Parameter 3: skoleaar
Parameter 4: termin
Parameter 5: fag
Parameter 6: niveau
Parameter 7: tid
Parameter 8: fritekst
Parameter 9: orderby

That's the name of the parameters, where I need the values.

Is this possible?

2 Answers 2

2

If you handle the Selecting event of the SqlDataSourceControl, the Command property of the SqlDataSourceEventArgs parameter will give you the DbCommand which is about to execute. From there, you can use the Parameters property to examine the parameters being passed to the command.

Sign up to request clarification or add additional context in comments.

Comments

1

I use a "stub" or debug method, as part of an event call from the asp:SqlDataSource tag:

<asp:SqlDataSource ID="dsProgram" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>" CancelSelectOnNullParameter="false"
    SelectCommand="<<<my select command for example>>" OnSelecting="dsProgram_Selecting">

Code Behind:

protected void dsProgram_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    foreach (SqlParameter P in e.Command.Parameters)
    {
        //for debugging only
    }   
}

Then I debug into the code and watch the 'P' value and all its elements.

Works great. Once I know what's going on, I delete the method and the event call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.