动态组合SQL语句方式实现批量更新的实例

2019-05-20 11:52:04于丽

            tran.Commit();//提交事务
        }
        catch (SqlException ex)
        {
            StrHelper.Alert(string.Format("SQL语句发生了异常,异常如下所示:n{0}", ex.Message));
            tran.Rollback();//出现异常,即回滚事务,防止出现脏数据
            return;
        }
        finally
        {
            sqlcon.Close();
        }
        if (result == i)//判断影响行数是否等于选中的数据行
        {
            StrHelper.Alert("数据更新成功!");
        }
        else
        {
            StrHelper.Alert("数据更新失败,事务已回滚!");
        }
        GV_DataBind();//重新绑定控件数据
        return;
    }
}

StrHelper.cs

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//引入如下命名空间
using System.Text.RegularExpressions;
using System.Text;

/// <summary>
///StrHelper 的摘要说明
/// </summary>
public class StrHelper
{
    public StrHelper(){}
    /// <summary>
    /// 截取字符串函数
    /// </summary>
    /// <param name="str">所要截取的字符串</param>
    /// <param name="num">截取字符串的长度</param>
    /// <returns></returns>
    static public string GetSubString(string str, int num)
    {
        #region
        return (str.Length > num) ? str.Substring(0, num) + "..." : str;
        #endregion
    }
    /// <summary>