日期:2014-05-17  浏览次数:21890 次

c#中如何获取实际执行的sql语句?
我的代码如下,如何获取实际执行的sql语句,另外我以下写法是不是有错?
C# code

DbCommand cmd = PkDbConnection.MainConn.CreateCommand();
                        cmd.CommandText = "update recharge_order set status=@status,ali_trade_no=@aliOrderSeq,confirm_time=@confirmTime where id=@order_id and status!=@curStatus";
                        cmd.Connection = PkDbConnection.MainConn;
                        DbParameter pa1 = PkDbConnection.MainFactory.CreateParameter();
                        pa1.DbType = DbType.Int16;
                        pa1.ParameterName = "@status";
                        pa1.Value = (int)status;
                        DbParameter pa2 = PkDbConnection.MainFactory.CreateParameter();
                        pa2.DbType = DbType.Int64;
                        pa2.ParameterName = "@order_id";
                        pa2.Value = orderId;
                        DbParameter pa3 = PkDbConnection.MainFactory.CreateParameter();
                        pa3.DbType = DbType.Int64;
                        pa3.ParameterName = "@aliOrderSeq";
                        pa3.Value = (int)OrderStatus.success;
                        DbParameter pa4 = PkDbConnection.MainFactory.CreateParameter();
                        pa4.DbType = DbType.AnsiString;
                        pa4.ParameterName = "@curStatus";
                        pa4.Value = aliOrderSeq;
                        DbParameter pa5 = PkDbConnection.MainFactory.CreateParameter();
                        pa5.DbType = DbType.AnsiString;
                        pa5.ParameterName = "@confirmTime";
                        pa5.Value = confirmTime;
                        cmd.Parameters.Add(pa1);
                        cmd.Parameters.Add(pa2);
                        cmd.Parameters.Add(pa3);
                        cmd.Parameters.Add(pa4);
                        cmd.Parameters.Add(pa5);
                      //  throw new Exception(cmd.Parameters.ToString());
                        return cmd.ExecuteNonQuery(); 



------解决方案--------------------
断点放 return cmd.ExecuteNonQuery(); 这里
 看cmd里面的属性
------解决方案--------------------
return cmd.ExecuteNonQuery(); 出加断点,快速监视cmd,学会调试是编程第一课。
------解决方案--------------------
执行的时候没有任何替换,仍然是参数化执行
------解决方案--------------------
探讨

按你们说的还是不行,监视里面cmd的CommandText= "update recharge_order set status=@status,ali_trade_no=@aliOrderSeq,confirm_time=@confirmTime where id=@order_id and status!=@curStatus"
并没有显示替换后的结果