Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the query that was executed from the SqlDataSource?

I have a sql query for my SelectCommand on my SqlDataSource. It looks like the following:

SELECT * FROM Books WHERE BookID = @BookID

A TextBox feeds the @BookID parameter using an Asp:ControlParameter.

When I view the SelectCommand when stepping through the code, I see this:

SELECT * FROM Books WHERE BookID = @BookID

What I want to actually see is that if the person types in 3 in the TextBox, I want to see

SELECT * FROM Books WHERE BookID = 3

I can't figure out how to access the above though?

like image 230
Xaisoft Avatar asked Mar 27 '09 13:03

Xaisoft


People also ask

How to use Sql data source?

Introduction. The SqlDataSource data source control represents data in an SQL relational database to data-bound controls. You can use the SqlDataSource control in conjunction with a data-bound control to retrieve data from a relational database and to display, edit, and sort data on a Web page with little or no code.

What is SQL datasource?

An SQL database data source represents a relational database or another source of data that can be accessed using an SQL database DSA. A wide variety of commercial relational databases are supported, such as Oracle, Sybase, and Microsoft SQL Server.

How to parameterize Sql in c#?

Using parameterized queries is a three-step process: Construct the SqlCommand command string with parameters. Declare a SqlParameter object, assigning values as appropriate. Assign the SqlParameter object to the SqlCommand object's Parameters property.


2 Answers

One way to view the actual query is by using SQL Profiler.

like image 167
irperez Avatar answered Oct 18 '22 15:10

irperez


The query is never executed as

SELECT * FROM Books WHERE BookID = 3

It's actually the parameterised query with the parameter passed.

You can do a "Find/Replace" on the query with the related parameters to see what it would look like.

like image 42
cjk Avatar answered Oct 18 '22 14:10

cjk