Exemple #1
0
        /**
         * @ 初始化数据库命令
         * */
        protected override bool InitSQLWithCmdText()
        {
            if (TableName.IsNullOrEmpty())
            {
                throw new ArgumentException("更新目标数据库表名:tablename不能为空!");
            }
            string updateString = GetUpdateFields();
            string whereString  = GetCondition();

            SQLCmdText = string.Format("UPDATE {0} SET {1} {2}", TableName, updateString, whereString);
            return(SQLCmdText.IsNotNullOrEmpty());
        }
Exemple #2
0
        /**
         * @ 初始化数据库命令
         * */
        protected override bool InitSQLWithCmdText()
        {
            if (TableName.IsNullOrEmpty())
            {
                throw new ArgumentException("插入目标数据库表名:tablename不能为空!");
            }
            StringBuilder cmdText = new StringBuilder();

            foreach (var item in Parameters)
            {
                StringBuilder insertBuilder = new StringBuilder(" INSERT");
                StringBuilder valuesBuilder = new StringBuilder(" VALUES(");
                insertBuilder.AppendFormat(" {0}(", TableName);
                List <string> fields = item.Fields;
                List <object> values = item.Values;
                int           len    = fields.Count;
                for (int i = 0; i < len; i++)
                {
                    string field = fields[i];
                    insertBuilder.AppendFormat(" [{0}]", field);
                    DbParameter para = AddParameter(field, values[i]);
                    valuesBuilder.AppendFormat("{0}", para.ParameterName);
                    if (i + 1 < len)
                    {
                        insertBuilder.Append(",");
                        valuesBuilder.Append(",");
                    }
                }
                valuesBuilder.Append(")");
                insertBuilder.Append(")");

                cmdText.AppendLine(string.Format("{0} {1}", insertBuilder.ToString(), valuesBuilder.ToString()));
            }
            SQLCmdText = cmdText.ToString().ToTrimSpace();
            return(SQLCmdText.IsNotNullOrEmpty());
        }