public string GetUpdateSQL(string tableNm, UpdateObject updatefield, WhereObject where) { StringBuilder builder = new StringBuilder(); //string updatefieldformat = string.Empty; string whereformat = string.Empty; builder.AppendFormat("{0} {1} Set ", ResFactory.ResManager.SQLUpdate, tableNm); if (updatefield == null) { throw new LibExceptionBase("param updatefield is not null"); } if (!string.IsNullOrEmpty(updatefield.UpdateFieldFormat)) { where.AppendWhereFormat(" ", updatefield.UpdateFieldFormat, updatefield.Values); updatefield.WhereFormat = where.GetUpdatefieldformat(); builder.Append(updatefield.UpdateFieldSQL); } whereformat = where.WhereFormat.Replace(updatefield.UpdateFieldSQL, ""); if (!string.IsNullOrEmpty(whereformat)) { return(string.Format("EXEC sp_executesql N'{0} where {1}',{2}", builder.ToString(), whereformat, where.ValueTostring)); } else if (!string.IsNullOrEmpty(updatefield.UpdateFieldFormat)) { return(string.Format("EXEC sp_executesql N'{0}',{1}", builder.ToString(), where.ValueTostring)); } return(string.Format("EXEC sp_executesql N'{0}'", builder.ToString())); }
public UpdateObject UpdateField(string format, params object[] values) { UpdateObject updateobj = new UpdateObject(); updateobj.WhereFormat = format; updateobj.Values = values; return(updateobj); }