首页 > 其他 > 详细

将截断字符串或二进制数据

时间:2016-01-13 17:50:21      阅读:225      评论:0      收藏:0      [点我收藏+]

//在插入语句中检查
private void FindInsertField(string sql, SqlParameter[] paras)
{
MatchCollection match = Regex.Matches(sql, "\\((.*?)\\)", RegexOptions.IgnoreCase);
string[] fields = new string[2];
for (int i = 0; i < 2; i++)
{
fields[i] = match[i].Groups[1].Value;
}

string[] fieldArr = fields[0].Split(‘,‘);
string sqlReplace = sql.Replace(fields[0], "{0}").Replace(fields[1], "{1}");
foreach (string s in fieldArr)
{
try
{
string sqlNew = string.Format(sqlReplace, s, "@" + s);
DbHelperSQL.ExecuteSql(sqlNew, paras);
}
catch (Exception ex)
{
throw ex;
}
}
}

//在更新语句中检查

private void FindUpdateField(string sql, SqlParameter[] paras)

{
Match match = Regex.Match(sql, "set ([\\w\\W]*) where", RegexOptions.IgnoreCase);
string fields = string.Empty;
if (match != null && match.Groups.Count > 1)
fields = match.Groups[1].Value;
else
return;

string[] fieldArr = fields.Split(‘,‘);
string sqlReplace = sql.Replace(fields, "{0}");
foreach (string s in fieldArr)
{
try
{
string sqlNew = string.Format(sqlReplace, s);
DbHelperSQL.ExecuteSql(sqlNew, paras);
}
catch (Exception ex)
{
throw ex;
}
}
}

将截断字符串或二进制数据

原文:http://www.cnblogs.com/dbolodb/p/5127768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!