打印SqlCommand及 SqlParameter的参数 /Write Sql Params

日前,将以前的Sql执行操作,改用了SqlHelper的操作方式。
为了调试方便,自定义了ParamsSql的打印方法。
当Params传递并执行后,即可调用下列方法,打印Params及Value值.
可以打印SqlClient的Sql Params.
Applog是自己定义的调试类。
可以换成Console.WriteLine/Response.Write等打印调试方法。这样很容易了解Procedure执行的过程,
又可以不用调试跟踪费时了。



ContractedBlock.gif ExpandedBlockStart.gif write_ParamsSql #region write_ParamsSql
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// write_ParamsSql
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="myParams"></param>
ExpandedSubBlockEnd.gif        
/// <param name="strProcedureName"></param>

InBlock.gif        public static void write_ParamsSql(SqlParameter [] myParams,String strProcedureName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String logSql 
= "";
InBlock.gif            
for (int i = 0; i < myParams.Length; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                logSql 
+= myParams[i].ParameterName + "='" + myParams[i].Value.ToString() + "',\n";  
ExpandedSubBlockEnd.gif            }

InBlock.gif            Applog.Log (
"execute " + strProcedureName + " " + logSql);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// write_ParamsSql
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="myCommand"></param>
ExpandedSubBlockEnd.gif        
/// <param name="strProcedureName"></param>

InBlock.gif        public static void write_ParamsSql(SqlCommand myCommand,String strProcedureName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String logSql 
= "";
InBlock.gif            
for (int i = 0; i < myCommand.Parameters.Count; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                logSql 
+= myCommand.Parameters[i].ParameterName + "='" + myCommand.Parameters[i].Value.ToString() + "',\n";  
ExpandedSubBlockEnd.gif            }

InBlock.gif            Applog.Log (
"execute " + strProcedureName + " " + logSql);
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

转载于:https://www.cnblogs.com/donetboy/archive/2005/12/09/293657.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值