public string InsertCmd(string TableName, List <object> _key, List <object> _value) { object[] key = _key.ToArray(); object[] value = _value.ToArray(); string sql = ""; if (NTool.isLenEquals(key, value)) { string val_str = ""; string _val_str = ""; for (int i = 0; i < key.Length; i++) { string insert_Str = string.Format("@{0}", key[i]); string _insert_Str = string.Format("{0}", key[i]); if (value.Length - 1 <= i || value.Length <= 1) { _val_str += _insert_Str; val_str += insert_Str; } else if (value.Length > 1) { val_str += insert_Str + ","; _val_str += _insert_Str + ","; } listSqlParam.Add(insert_Str, value[i] + ""); } sql = string.Format("insert into {0}({1}) values({2}) ", TableName, _val_str, val_str); } return(sql); }
public string UpdateCmd(string TableName, object[] key, object[] value, string where) { string sql = ""; if (NTool.isLenEquals(key, value)) { string val_str = ""; for (int i = 0; i < key.Length; i++) { string upDate_Str = string.Format("@{0}", key[i]); string _upDate_Str = string.Format("{0}", key[i]); if (value.Length - 1 <= i || value.Length <= 1) { val_str += _upDate_Str + "=" + upDate_Str; } else if (value.Length > 1) { val_str += _upDate_Str + "=" + upDate_Str + ","; } listSqlParam.Add(upDate_Str, value[i] + ""); } if (!string.IsNullOrEmpty(where)) { where = " where " + where; } sql = string.Format("update {0} set {1} {2} ", TableName, val_str, where); //UPDATE Person SET FirstName = 'Fred' WHERE LastName = 'Wilson' } return(sql); }