您可以使用此解决方法将 ParameterName 替换为它的值,但它不好,因为您需要自己管理值格式,并且它可能很慢
,并且您需要在执行 Insert 后获取参数
代码:
var usersTableAdapter = new testDataSetTableAdapters.usersTableAdapter();
usersTableAdapter.Insert(4, "home", "origin", "email@host.com", "realname", "spec", 1, "username", "usernick", "whereform");
var cmd = usersTableAdapter.Adapter.InsertCommand;
var text = cmd.CommandText;
var sb = new StringBuilder(text);
foreach (SqlParameter cmdParam in cmd.Parameters)
{
if (cmdParam.Value is string)
sb.Replace(cmdParam.ParameterName, string.Format("'{0}'", cmdParam.Value));
else
sb.Replace(cmdParam.ParameterName, cmdParam.Value.ToString());
}
Console.WriteLine(sb.ToString());