1/1页1 跳转到查看:133
发新话题 回复该主题

ADO.Net中使用参数化SQL语句 如何获得实际运行的SQL语句

ADO.Net中使用参数化SQL语句 如何获得实际运行的SQL语句

项目里想要用参数化的Sql语句(没有用存储过程)  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
如:"SELECT   *   FROM   People   where   id=@a   and   name=@b"  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
然后对参数附值:  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
Cmd.Parameters.AddWithValue("@a","1")  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
Cmd.Parameters.AddWithValue("@b","jack")  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
现在想要获得最后执行的实际Sql语句,也就是:  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
SELECT   *   FROM   People   where   id=1   and   name= "jack "  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
请问如何得到/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

string str = Cmd.CommandText;/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

Cmd.CommandText/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

不好意思,标题中的代码是我抄别的帖子的,我的是这么写的(大概): /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
string sss=“select VC_APPLICATIONSID FROM  DECISION  where APP=:APP”; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
OracleParameter[] parameters = { /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
       new OracleParameter(":VC_APPLICATIONSID",OracleType.VarChar,200)}; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
parameters[0].Value = "123456"; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
cmd.CommandText = cmdText; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
foreach (OracleParameter parm in cmdParms) /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
{ /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
    cmd.Parameters.Add(parameters ); /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
} /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
OracleDataAdapter da = new OracleDataAdapter(cmd) /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
da.Fill(ds); /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
--------------------------- /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
2楼的string str = Cmd.CommandText; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
结果为:select VC_APPLICATIONSID FROM  DECISION  where APP=:APP/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

不好意思,标题中的代码是我抄别的帖子的,我的是这么写的(大概): /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
string sss=“select VC_APPLICATIONSID FROM  DECISION  where APP=:APP”; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
OracleParameter[] parameters = { /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
       new OracleParameter(":VC_APPLICATIONSID",OracleType.VarChar,200)}; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
parameters[0].Value = "123456"; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
cmd.CommandText = cmdText; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
foreach (OracleParameter parm in cmdParms) /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
{ /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
    cmd.Parameters.Add(parameters ); /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
} /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
OracleDataAdapter da = new OracleDataAdapter(cmd) /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
da.Fill(ds); /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
  /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
--------------------------- /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
2楼的string str = Cmd.CommandText; /°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O
结果为:select VC_APPLICATIONSID FROM  DECISION  where APP=:APP/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

Cmd.CommandText.ToString();呢?/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 

sorry,试了一下,不行。/°Î!&ÏS®À®forum.entlib.net.cnx5%æ ™á´O

TOP

 
1/1页1 跳转到
发表新主题 回复该主题