Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a hard time to debug asp.net webform application using SqlDataSource. For the insert command -

DataSource.ConnectionString = ConnectionManager.ConnectionString;
DataSource.ProviderName = ConnectionManager.ProviderName;
DataSource.InsertCommand = "INSERT INTO tblTest(ID, test1, test2, test3, test4, test5, test6, test7, test8) Values(@ID, @test1, @test2, @test3, @test4, @test5, @test6, @test7, @test8)"

I am looking for the complete T-SQL insert string with filled parameter values such as

INSERT INTO tblTest(ID, test1, test2, test3, test4, test5, test6, test7, test8) Values(a0, 1, 2, 3, 4, 5, 6, 7, 8)

Currently I can set the a break-point in

protected void DataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
}

But SqlDataSourceStatusEventArgs only has InsertCommand and parameter collections in separate objects. It is very inconvenient to put them together as a T-SQL command.

How do you guys debug SqlDataSource in Visual Studio?

Thanks

share|improve this question

1 Answer 1

The following MSDN page gives you an example of how to obtain debug information after an insert.

Sub On_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
    Dim command As DbCommand 
    command = e.Command

    ' The label displays the primary key of the recently inserted row.
    Label1.Text = command.Parameters("@PK_New").Value.ToString()    

    ' Explicitly call DataBind to refresh the data
    ' and show the newly inserted row.
    GridView1.DataBind()
 End Sub 'On_Inserted

SqlDataSource actually supports a lot of other events, which you can also find on MSDN.

Finally.... maybe consider using EntityFramework (shudder) or one of the other leading OOR tools such as LLBLGEN (win!). They abstract the database into an object model making development, and debug, much easier.

share|improve this answer
    
Thanks for your answer. The way to obtain the debug info in the link is too clumsy to me. I have to print out each parameter value out to construct a T-SQL command in this way. Is there any better way? –  Don Dec 23 '13 at 2:51
    
Yes, see my last sentence :) –  robnick Dec 24 '13 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.