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(!CC21A118B1B5250!288.entry). It seems it needs some changes to make it work with ObjectDataSource. Here is the code:
//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 =



strValue = param.Value.ToString();

strSQL += param.Key.ToString() +

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





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


End Sub



Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s