Show ObjectDataSource ‘s SQL statement in ASP.NET


In my previous post, I posted a tip for how to get the parsed SQL statement of an SQLDataSource in ASP.NET(http://jingyang.spaces.live.com/blog/cns!CC21A118B1B5250!288.entry). It seems it needs some changes to make it work with ObjectDataSource. Here is the code:
C#:
//using System.Collections.Specialized;
 

protected void ObjectDataSource1_Updating(object sender, ObjectDataSourceMethodEventArgs e)

{

IOrderedDictionary myCollection = (IOrderedDictionary)e.InputParameters;

IEnumerator ie = myCollection.GetEnumerator();

string strSQL = string.Empty;

while ((ie.MoveNext()))

{

DictionaryEntry param = (DictionaryEntry)ie.Current;

string strValue = string.Empty;

if (param.Value == null)

strValue =

"NULL";

else

strValue = param.Value.ToString();

strSQL += param.Key.ToString() +

"=" + strValue + "<BR />";

}

Response.Write(strSQL.ToString());

}

VB.NET:

Protected Sub ObjectDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Updating

Dim myCollection As IOrderedDictionary = e.InputParameters()

Dim ie As IEnumerator = myCollection.GetEnumerator

Dim strSQL As String = ""

While (ie.MoveNext())

Dim param As System.Collections.DictionaryEntry = ie.Current()

strSQL += param.Key &

"=" & param.Value() & "<BR />"

End While

Response.Write(strSQL.ToString())

End Sub

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s