Пример #1
0
        public int Update(string _tableName)
        {
            this.tableName = _tableName;
            this.fieldName = string.Empty;
            this.SqlCmd    = "UPDATE [" + this.tableName + "] SET ";
            for (int index = 0; index < this.alFieldItems.Count - 1; ++index)
            {
                DbOperHandler dbOperHandler = this;
                dbOperHandler.SqlCmd = dbOperHandler.SqlCmd + "[" + ((DbKeyItem)this.alFieldItems[index]).fieldName + "]";
                this.SqlCmd         += "=";
                this.SqlCmd         += "@para";
                this.SqlCmd         += index.ToString();
                this.SqlCmd         += ",";
            }
            DbOperHandler dbOperHandler1 = this;

            dbOperHandler1.SqlCmd = dbOperHandler1.SqlCmd + "[" + ((DbKeyItem)this.alFieldItems[this.alFieldItems.Count - 1]).fieldName + "]";
            this.SqlCmd          += "=";
            this.SqlCmd          += "@para";
            this.SqlCmd          += (this.alFieldItems.Count - 1).ToString();
            if (this.ConditionExpress != string.Empty)
            {
                DbOperHandler dbOperHandler2 = this;
                dbOperHandler2.SqlCmd = dbOperHandler2.SqlCmd + " where " + this.ConditionExpress;
            }
            this.cmd.CommandText = this.SqlCmd;
            this.GenParameters();
            return(this.cmd.ExecuteNonQuery());
        }
Пример #2
0
        public int Insert(string _tableName)
        {
            this.tableName = _tableName;
            this.fieldName = string.Empty;
            this.SqlCmd    = "insert into [" + this.tableName + "](";
            string str = " values(";

            for (int index = 0; index < this.alFieldItems.Count - 1; ++index)
            {
                DbOperHandler dbOperHandler = this;
                dbOperHandler.SqlCmd = dbOperHandler.SqlCmd + "[" + ((DbKeyItem)this.alFieldItems[index]).fieldName + "]";
                this.SqlCmd         += ",";
                str = str + "@para" + index.ToString() + ",";
            }
            DbOperHandler dbOperHandler1 = this;

            dbOperHandler1.SqlCmd = dbOperHandler1.SqlCmd + "[" + ((DbKeyItem)this.alFieldItems[this.alFieldItems.Count - 1]).fieldName + "]";
            this.SqlCmd          += ") ";
            this.SqlCmd          += str + "@para" + (this.alFieldItems.Count - 1).ToString() + ")";
            this.cmd.CommandText  = this.SqlCmd;
            this.GenParameters();
            this.cmd.ExecuteNonQuery();
            int num = 0;

            try
            {
                this.cmd.CommandText = "select @@identity as id";
                num = Convert.ToInt32(this.cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
            }
            return(num);
        }