提交数据时生成的SQL脚本便于实时跟踪
提交数据时生成的SQL脚本便于实时跟踪
扫一扫加作者微信
绑定SqlDataAdapter.RowUpdating事件:
SqlDataAdapter adp = new SqlDataAdapter();
adp.RowUpdating += new SqlRowUpdatingEventHandler(OnAdapterRowUpdating);
dalBase基类增加下面代码:
C# Code:
/// <summary>
/// 提交记录时生成的SQL脚本
/// </summary>
protected string _LastRowSQLText = "";
/// <summary>
/// 生成带参数的SQL脚本
/// </summary>
protected bool _GenerateLastRowSQLText = false;
/// <summary>
/// 适配器提交每条记录时触发的事件
/// </summary>
protected virtual void OnAdapterRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
if (_GenerateLastRowSQLText)
_LastRowSQLText = BuildSQLText(e.Command.Parameters);
}
/// <summary>
/// 生成带参数的SQL脚本
/// </summary>
/// <param name="parameters">SqlCommand参数</param>
/// <returns></returns>
private string BuildSQLText(SqlParameterCollection parameters)
{
StringBuilder sb = new StringBuilder();
foreach (SqlParameter p in parameters)
{
sb.AppendLine(p.ParameterName "=" (((p.Value == null) || (p.Value == DBNull.Value) || (p.Value.ToString()=="")) ?
"null" : p.Value.ToString()) ", ");
}
return sb.ToString();
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
/// <summary>
/// 提交记录时生成的SQL脚本
/// </summary>
protected string _LastRowSQLText = "";
/// <summary>
/// 生成带参数的SQL脚本
/// </summary>
protected bool _GenerateLastRowSQLText = false;
/// <summary>
/// 适配器提交每条记录时触发的事件
/// </summary>
protected virtual void OnAdapterRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
if (_GenerateLastRowSQLText)
_LastRowSQLText = BuildSQLText(e.Command.Parameters);
}
/// <summary>
/// 生成带参数的SQL脚本
/// </summary>
/// <param name="parameters">SqlCommand参数</param>
/// <returns></returns>
private string BuildSQLText(SqlParameterCollection parameters)
{
StringBuilder sb = new StringBuilder();
foreach (SqlParameter p in parameters)
{
sb.AppendLine(p.ParameterName "=" (((p.Value == null) || (p.Value == DBNull.Value) || (p.Value.ToString()=="")) ?
"null" : p.Value.ToString()) ", ");
}
return sb.ToString();
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网