예제 #1
0
        /// <summary>
        /// 获取更新的语句
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="Columns"></param>
        /// <param name="Keys"></param>
        /// <param name="connType"></param>
        /// <returns></returns>
        public static string GetUpdateSqlStr(this DbConnType connType, string tableName, string[] Columns, string[] Keys)
        {
            StringBuilder strbld = new StringBuilder(512);

            strbld.AppendFormat("Update {0} set ", connType.DbDelimiter(tableName));
            for (int i = 0, count = Columns.Length; i < count; i++)
            {
                string fieldName = Columns[i];
                if (Keys.Contains(fieldName))
                {
                    continue;
                }
                string parName = connType.TreatParaName(fieldName);
                strbld.AppendFormat("{0}={1},", connType.DbDelimiter(fieldName), parName);
            }
            strbld.Remove(strbld.Length - 1, 1);
            strbld.Append(" where ");
            for (int i = 0, count = Keys.Length; i < count; i++)
            {
                if (0 != i)
                {
                    strbld.Append(" and ");
                }
                string fieldName = Keys[i];
                string parName   = connType.TreatParaName(fieldName);
                strbld.AppendFormat("{0}={1}", connType.DbDelimiter(fieldName), parName);
            }
            return(strbld.ToString());
        }
예제 #2
0
 public static string DbDelimiter(this string TableOrFieldName, DbConnType dbConnType, bool checkSymExists = false)
 => dbConnType.DbDelimiter(TableOrFieldName, checkSymExists);