开发者

How to get the SQL actually executed by a parameterized query in .Net (VB or C#)?

Is there a straight forward way to view the SQL command text actually executed against the underlying database by a DbCommand object (i.e. after the parameters have been processed into a statement)?

Here the detail: I'm using VB.Net 3.5 and have a factory object (DbProviderFactory) and a connection (System.Data.IDbConnection). I am using the factory to create a new command object using the DbProviderFactory.CreateCommand() method and then assigning a parametrized query to the CommandText property of the command. Later on I create and associate some parameters with the query (created using the DbProviderFactory).

This is great, but I want to get a look at the actual SQL statement generated by the command object. I am currently testing this against a SQLite database, but wondered if there were a 开发者_StackOverflow中文版general approach which would work.


The actual SQL executed by the server is exactly what you wrote. The parameters are sent separately from the command itself, so they're actually never replaced with their value in the SQL command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜