使用 MySqlCommand 参数时如何查看命令字符串? [英] How can I see the command string when using MySqlCommand parameters?

查看:35
本文介绍了使用 MySqlCommand 参数时如何查看命令字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

MySqlCommand cmd = new MySqlCommand(
    "SELECT * FROM DB_name_here WHERE some_field =@some_value;"
);

cmd.Parameters.AddWithValue("@some_value", some_string_here);

我可以将它作为一个简单的字符串取回用于调试目的吗,它说:

Can I get it back as a simple string for debug purposes, that says:

SELECT * FROM DB_name_here WHERE some_field =some_string_here;

明显的 cmd.ToString() 很快让我失望,返回一个 MySql.Data.MySqlClient.MySqlCommand.
cmd.CommandText 将返回带有参数的字符串(在我的情况下为 @some_value).

The obvious cmd.ToString() failed me promptly, returning a MySql.Data.MySqlClient.MySqlCommand.
The cmd.CommandText will return the string with the parameter (@some_value in my case).

有什么建议吗?

推荐答案

根据这个答案不能直接做.

来自答案:

任何时候都不会生成完整的 SQL 字符串.

At no point in time a complete SQL string is generated.

(有关变通方法,请参阅那里的其他答案.尤其是 https://stackoverflow.com/a/265261/939213.)

(For workarounds see the other answers there. especially https://stackoverflow.com/a/265261/939213.)

这篇关于使用 MySqlCommand 参数时如何查看命令字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆