public static string GetInsertSqlScript(string tableName, Dictionary <string, string> data, bool setInsertOn = true) { var sql = string.Empty; string columns = ""; string values = ""; ColumnHelper.SetDefaultColumnValues(data, setInsertOn); foreach (KeyValuePair <string, string> val in data) { columns += string.Format(@" {0},", val.Key.ToString()); values += string.Format(@" '{0}',", ConvertionHelper.CleanStringForSQL(val.Value)); } columns = columns.Substring(0, columns.Length - 1); values = values.Substring(0, values.Length - 1); sql = string.Format(@"INSERT INTO {0}({1}) values({2})", tableName, columns, values); return(sql); }
private static string GetUpdateSqlFieldScript(Dictionary <string, string> data, bool setModifyOn = true) { string columnValuePair = ""; ColumnHelper.SetDefaultColumnValues(data); if (setModifyOn) { if (data.ContainsKey(DbCIC.ModifyOn)) { data[DbCIC.ModifyOn] = DateTime.Now.ToString(); } } foreach (KeyValuePair <string, string> val in data) { columnValuePair += string.Format(@" {0} = '{1}',", val.Key.ToString(), ConvertionHelper.CleanStringForSQL(val.Value)); } columnValuePair = columnValuePair.Substring(0, columnValuePair.Length - 1); return(columnValuePair); }