Wednesday, August 11, 2010

How to print out the sql statement in asp.net 2.0 gridview?

I 'd like to print the executing sql statement where the databind with asp.net 2.0 gridview. Since in 2.0, the grid view is auto generated, I can' find an explict way to show the running sql statement.





thanks,How to print out the sql statement in asp.net 2.0 gridview?
If you configured a gridview with the designer, and you are using a SQLDataSource (named SQLDataSource1 by default):





Create a label on your page. Say it is:


%26lt;asp:label runat=';server'; id=';lblSQL';/%26gt;





In your Page_Load event:





C#


lblSQL.Text = SQLDataSource1.SelectCommand;





VB


lblSQL.Text = SQLDataSource1.SelectCommandHow to print out the sql statement in asp.net 2.0 gridview?
That wasn't part of your original question, but if you look at the .aspx code you should see a section under the SQLDataSource named %26lt;SelectParameters%26gt;. You could use this information to perform a replace on the parameter tokens in the SelectCommand with the values.

Report Abuse

No comments:

Post a Comment