예제 #1
0
파일: DAL.cs 프로젝트: morimizu/repo
        private static SDC.DbCommand BuildCommand(string sproc, List <ParamStruct> list)
        {
            SDC.DbProviderFactory factory = SDC.DbProviderFactories.GetFactory(Properties.Settings.Default.provider);

            SDC.DbCommand comm = factory.CreateCommand();

            comm.CommandText = sproc;
            comm.CommandType = System.Data.CommandType.StoredProcedure;


            SDC.DbParameter param = factory.CreateParameter();


            foreach (ParamStruct item in list)
            {
                param.ParameterName = item.paramId;
                param.Value         = item.paramValue;
                param.DbType        = item.paramType;
                param.Size          = item.paramLength;
                param.Direction     = item.paramDirection;
                comm.Parameters.Add(param);
                param = factory.CreateParameter();
            }

            return(comm);
        }
예제 #2
0
        internal IDbDataParameter CreateParameter(string parameterName, object value)
        {
            IDbDataParameter param = ProviderFactory.CreateParameter();

            param.ParameterName = parameterName;
            param.Value         = value;
            if (param.DbType == System.Data.DbType.DateTime)
            {
                if (param is System.Data.OleDb.OleDbParameter odp)
                {
                    odp.OleDbType = System.Data.OleDb.OleDbType.Date;
                }
            }
            return(param);
        }
        private static object CreateObject(DbProviderFactory factory, ProviderSupportedClasses kindOfObject, string providerName)
        {
            switch (kindOfObject)
            {
                case ProviderSupportedClasses.DbConnection:
                    return factory.CreateConnection();

                case ProviderSupportedClasses.DbDataAdapter:
                    return factory.CreateDataAdapter();

                case ProviderSupportedClasses.DbParameter:
                    return factory.CreateParameter();

                case ProviderSupportedClasses.DbCommand:
                    return factory.CreateCommand();

                case ProviderSupportedClasses.DbCommandBuilder:
                    return factory.CreateCommandBuilder();

                case ProviderSupportedClasses.DbDataSourceEnumerator:
                    return factory.CreateDataSourceEnumerator();

                case ProviderSupportedClasses.CodeAccessPermission:
                    return factory.CreatePermission(PermissionState.None);
            }
            throw new InternalException(string.Format(CultureInfo.CurrentCulture, "Cannot create object of provider class identified by enum {0} for provider {1}", new object[] { Enum.GetName(typeof(ProviderSupportedClasses), kindOfObject), providerName }));
        }
 internal static DbParameter CreateParameter(DbProviderFactory factory,
     Action<DbParameter> setup)
 {
     DbParameter parameter = factory.CreateParameter();
     setup(parameter);
     return parameter;
 }
        //public static DbParameter CreateParameter(this DbProviderFactory dbFactory, string parameterName, object value)
        /// <summary>
        /// Create a DbParameter with the specified name and value.
        /// </summary>
        public static DbParameter CreateParameter(DbProviderFactory dbFactory, string parameterName, object value)
        {
            if (dbFactory == null) throw new ArgumentNullException("dbFactory");

            var parameter = dbFactory.CreateParameter();
            parameter.ParameterName = parameterName;
            parameter.Value = value;
            return parameter;
        }
        /// <summary>
        /// Método que cria e retorna um parâmetro DbParameter do tipo da DbFactory da tag AppSettings do web.config.
        /// </summary>
        /// <param name="_nome">Nome do parâmetro.</param>
        /// <param name="_valor">Valor do parâmetro.</param>
        /// <param name="_tipo">Tipo do parâmetro (DbType).</param>
        public static DbParameter Parametro(string _nome, object _valor, DbType _tipo)
        {
            factory = DBConnectionProvider.GetDbFactory();
            DbParameter parameter = factory.CreateParameter();

            parameter.ParameterName = _nome;
            parameter.Value  = _valor;
            parameter.DbType = _tipo;

            return parameter;
        }
예제 #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <param name="factory"></param>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 public static void AddParameterToCommand(
     DbCommand command,
     DbProviderFactory factory,
     System.Data.DbType type,
     String name,
     object value)
 {
     DbParameter param = factory.CreateParameter();
     param.DbType = type;
     param.ParameterName = GetParameterName(command, name);
     param.Value = value;
     command.Parameters.Add(param);
 }
예제 #8
0
        private DbCommand BuildSelectCommand(System.Data.Common.DbProviderFactory provider, DbConnection con, string queryString, params dynamic[] args)
        {
            DbCommand com = provider.CreateCommand();

            com.CommandTimeout = 30;
            com.Connection     = con;
            com.CommandText    = queryString;
            com.CommandType    = CommandType.Text;
            foreach (var param in args)
            {
                DbParameter par = provider.CreateParameter();
                par.Direction     = ParameterDirection.Input;
                par.ParameterName = param.Name;
                par.Value         = param.Value;
                com.Parameters.Add(par);
            }
            return(com);
        }
 private void AddCommandInitStatements(IList statements, CodeExpression commandExpression, DbSourceCommand command, DbProviderFactory currentFactory, bool isFunctionsDataComponent)
 {
     if (((statements == null) || (commandExpression == null)) || (command == null))
     {
         throw new InternalException("Argument should not be null.");
     }
     Type parameterType = currentFactory.CreateParameter().GetType();
     Type type = currentFactory.CreateCommand().GetType();
     CodeExpression parameterVariable = null;
     statements.Add(CodeGenHelper.Assign(commandExpression, CodeGenHelper.New(CodeGenHelper.GlobalType(type), new CodeExpression[0])));
     if (isFunctionsDataComponent)
     {
         commandExpression = CodeGenHelper.Cast(CodeGenHelper.GlobalType(type), commandExpression);
     }
     if ((((DbSource) command.Parent).Connection == null) || ((this.designTable.Connection != null) && (this.designTable.Connection == ((DbSource) command.Parent).Connection)))
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionPropertyName)));
     }
     else
     {
         Type type3 = currentFactory.CreateConnection().GetType();
         IDesignConnection connection = ((DbSource) command.Parent).Connection;
         CodeExpression propertyReference = null;
         if (connection.PropertyReference == null)
         {
             propertyReference = CodeGenHelper.Str(connection.ConnectionStringObject.ToFullString());
         }
         else
         {
             propertyReference = connection.PropertyReference;
         }
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.New(CodeGenHelper.GlobalType(type3), new CodeExpression[] { propertyReference })));
     }
     statements.Add(QueryGeneratorBase.SetCommandTextStatement(commandExpression, command.CommandText));
     statements.Add(QueryGeneratorBase.SetCommandTypeStatement(commandExpression, command.CommandType));
     if (command.Parameters != null)
     {
         foreach (DesignParameter parameter in command.Parameters)
         {
             parameterVariable = QueryGeneratorBase.AddNewParameterStatements(parameter, parameterType, currentFactory, statements, parameterVariable);
             statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(commandExpression, "Parameters"), "Add", new CodeExpression[] { parameterVariable })));
         }
     }
 }
예제 #10
0
        public int ExecuteNonQuery(String queryString, bool silence, params dynamic[] args)
        {
            string lib = GetProviderFactoryLib(providerName);

            System.Data.Common.DbProviderFactory provider = RegisterProvider(providerName);
            DbConnection con = provider.CreateConnection();

            con.ConnectionString = BuildConnectionString(providerName, this.dbName);
            DbCommand com = provider.CreateCommand();

            com.CommandTimeout = 30;
            com.Connection     = con;
            com.CommandText    = queryString;
            com.CommandType    = CommandType.Text;
            foreach (var param in args)
            {
                DbParameter par = provider.CreateParameter();
                par.Direction     = ParameterDirection.Input;
                par.ParameterName = param.Name;
                par.Value         = param.Value;
                com.Parameters.Add(par);
            }

            int rowsAffected = 0;

            try
            {
                con.Open();
                object result = com.ExecuteNonQuery();
                if (result != null)
                {
                    rowsAffected = Convert.ToInt32(result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            con.Close();
            return(rowsAffected);
        }
예제 #11
0
        public DataTable ExecuteQuery(String queryString, params dynamic[] args)
        {
            readConectionSettings();
            string lib = GetProviderFactoryLib(providerName);

            provider             = RegisterProvider(providerName);
            con                  = provider.CreateConnection();
            con.ConnectionString = BuildConnectionString(providerName, this.dbName);
            DataTable table = null;
            DbCommand com   = provider.CreateCommand();

            com.CommandTimeout        = 30;
            com.Connection            = con;
            com.CommandText           = queryString;
            com.CommandType           = CommandType.Text;
            dataSet                   = new DataSet();
            dataAdapter               = provider.CreateDataAdapter();
            dataAdapter.SelectCommand = com;
            foreach (var param in args)
            {
                DbParameter par = provider.CreateParameter();
                par.Direction     = ParameterDirection.Input;
                par.ParameterName = param.Name;
                par.Value         = param.Value;
                dataAdapter.SelectCommand.Parameters.Add(par);
            }

            try
            {
                con.Open();
                dataAdapter.Fill(dataSet);
                table = dataSet.Tables[0];
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                throw ex;
            }
            con.Close();
            return(table);
        }
예제 #12
0
        public DataTable getDataQuery(String queryString, params dynamic[] args)
        {
            if (con == null)
            {
                LoadConnection();
            }
            DataTable table = null;
            DbCommand com   = provider.CreateCommand();

            com.CommandTimeout        = 30;
            com.Connection            = this.con;
            com.CommandText           = queryString;
            com.CommandType           = CommandType.Text;
            dataSet                   = new DataSet();
            dataAdapter               = provider.CreateDataAdapter();
            dataAdapter.SelectCommand = com;
            if (args != null && args.Length > 0)
            {
                foreach (var param in args)
                {
                    DbParameter par = provider.CreateParameter();
                    par.Direction     = ParameterDirection.Input;
                    par.ParameterName = param.Name;
                    par.Value         = param.Value;
                    dataAdapter.SelectCommand.Parameters.Add(par);
                }
            }
            try
            {
                con.Open();
                dataAdapter.Fill(dataSet);
                table = dataSet.Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
            con.Close();
            return(table);
        }
        private void UpdateTags(IPublishable parent, DbConnection conn, DbProviderFactory provider)
        {
            int type = 0;
            if (parent is Training)
            {
                type = 1;

            }
            string sqlQuery = "DELETE FROM " + tablePrefix + "Tags WHERE ParentID = " + parmPrefix + "id and ParentType="+type;
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = parent.Id.ToString() ;
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (string tag in (parent is Training) ? ((Training)parent).Tags : ((Curricula)parent).Tags)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + "Tags (ParentID,ParentType, Tag) " +
                        "VALUES (" + parmPrefix + "parentid, " + parmPrefix + "parenttype, " + parmPrefix + "tag)";
                    cmd.Parameters.Clear();

                    DbParameter dpTrainingID = provider.CreateParameter();
                    dpTrainingID.ParameterName = parmPrefix + "parentid";
                    dpTrainingID.Value = parent.Id.ToString();
                    cmd.Parameters.Add(dpTrainingID);
                    DbParameter dpParentType = provider.CreateParameter();
                    dpParentType.ParameterName = parmPrefix + "parenttype";
                    dpParentType.Value = type;
                    cmd.Parameters.Add(dpParentType);
                    DbParameter dpTag = provider.CreateParameter();
                    dpTag.ParameterName = parmPrefix + "tag";
                    dpTag.Value = tag;
                    cmd.Parameters.Add(dpTag);

                    cmd.ExecuteNonQuery();
                }
            }
        }
        private void UpdateRessForExcellent(Excellent parent, DbConnection conn, DbProviderFactory provider)
        {
            string table = "ExcellentRes";
            string key = "ExcellentID";

            string sqlQuery = "DELETE FROM " + tablePrefix + table + " WHERE " + key + " = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = parent.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (Res info in parent.Ress)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + table + " (" + key + ", ResID) " +
                        "VALUES (" + parmPrefix + "pid, " + parmPrefix + "ResID)";
                    cmd.Parameters.Clear();
                    DbParameter dpcID = provider.CreateParameter();
                    dpcID.ParameterName = parmPrefix + "pid";
                    dpcID.Value = parent.Id.ToString();
                    cmd.Parameters.Add(dpcID);

                    DbParameter dpInfoID = provider.CreateParameter();
                    dpInfoID.ParameterName = parmPrefix + "ResID";
                    dpInfoID.Value = info.Id.ToString();
                    cmd.Parameters.Add(dpInfoID);

                    cmd.ExecuteNonQuery();

                }
            }
        }
        private void UpdateFields(IPublishable parent, DbConnection conn, DbProviderFactory provider)
        {
            string table = "CurriculaField";
            string key = "CurriculaID";
            if (parent is Training)
            {

                table = "TrainingField";
                key = "TrainingID";
            }
            string sqlQuery = "DELETE FROM " + tablePrefix + table + " WHERE " + key + " = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = parent.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (Field fld in parent.Fields)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + table + " (" + key + ", FieldID) " +
                        "VALUES (" + parmPrefix + "id, " + parmPrefix + "fld)";
                    cmd.Parameters.Clear();
                    DbParameter dpPostID = provider.CreateParameter();
                    dpPostID.ParameterName = parmPrefix + "id";
                    dpPostID.Value = parent.Id.ToString();
                    cmd.Parameters.Add(dpPostID);
                    DbParameter dpfld = provider.CreateParameter();
                    dpfld.ParameterName = parmPrefix + "fld";
                    dpfld.Value = fld.Id.ToString();
                    cmd.Parameters.Add(dpfld);

                    cmd.ExecuteNonQuery();
                }
            }
        }
        private void UpdateCurriculaInfos(Curricula parent, DbConnection conn, DbProviderFactory provider)
        {
            string table = "CurriculaInfo";
            string key = "CurriculaID";

            string sqlQuery = "DELETE FROM " + tablePrefix + table + " WHERE " + key + " = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = parent.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (CurriculaInfo info in parent.CurriculaInfos)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + table + " (" + key + ", InfoID,StartDate,EndDate,Cast,CityTown,IsPublished) " +
                        "VALUES (" + parmPrefix + "pid, " + parmPrefix + "InfoID, " + parmPrefix + "StartDate, " + parmPrefix + "EndDate, " + parmPrefix + "Cast, " + parmPrefix + "CityTown, " + parmPrefix + "IsPublished)";
                    cmd.Parameters.Clear();
                    DbParameter dpcID = provider.CreateParameter();
                    dpcID.ParameterName = parmPrefix + "pid";
                    dpcID.Value = parent.Id.ToString();
                    cmd.Parameters.Add(dpcID);

                    DbParameter dpInfoID = provider.CreateParameter();
                    dpInfoID.ParameterName = parmPrefix + "InfoID";
                    dpInfoID.Value = info.Id.ToString();
                    cmd.Parameters.Add(dpInfoID);

                    DbParameter dpStartDate = provider.CreateParameter();
                    dpStartDate.ParameterName = parmPrefix + "StartDate";
                    dpStartDate.Value = info.StartDate;
                    cmd.Parameters.Add(dpStartDate);

                    DbParameter dpEndDate = provider.CreateParameter();
                    dpEndDate.ParameterName = parmPrefix + "EndDate";
                    dpEndDate.Value = info.EndDate;
                    cmd.Parameters.Add(dpEndDate);

                    DbParameter dpCast = provider.CreateParameter();
                    dpCast.ParameterName = parmPrefix + "Cast";
                    dpCast.Value = info.Cast;
                    cmd.Parameters.Add(dpCast);

                    DbParameter dpCityTown = provider.CreateParameter();
                    dpCityTown.ParameterName = parmPrefix + "CityTown";
                    dpCityTown.Value = info.CityTown;
                    cmd.Parameters.Add(dpCityTown);

                    DbParameter dpIsPublished = provider.CreateParameter();
                    dpIsPublished.ParameterName = parmPrefix + "IsPublished";
                    dpIsPublished.Value = info.IsPublished;
                    cmd.Parameters.Add(dpIsPublished);

                    cmd.ExecuteNonQuery();

                }
            }
        }
        private void UpdateComments(IPublishable parent, DbConnection conn, DbProviderFactory provider)
        {
            int type = 0;
            if (parent is Training)
            {
                type = 1;

            }
            string sqlQuery = "DELETE FROM " + tablePrefix + "Comments WHERE ParentID = " + parmPrefix + "id and ParentType=" + type;
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = parent.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (Comment comment in parent.Comments)
                {
                    sqlQuery = "INSERT INTO " + tablePrefix + "Comments (CommentID,ParentID,ParentType,CommentDate,Author,Count,Sex,Phone,Mobile,Email,Company,QQ_msn,Comment,IsDispose,DisposeBy,Country,IP) " +
                                        "VALUES (@commentid, @parentid, @type, @date, @author,@count,@sex,@phone,@mobile, @email, @company,@qq_msn,@comment, @isapproved, @moderatedby, @country, @ip)";
                    if (parmPrefix != "@")
                        sqlQuery = sqlQuery.Replace("@", parmPrefix);
                    cmd.CommandText = sqlQuery;
                    cmd.Parameters.Clear();
                    DbParameter dpCommentID = provider.CreateParameter();
                    dpCommentID.ParameterName = parmPrefix + "commentid";
                    dpCommentID.Value = comment.Id.ToString();
                    cmd.Parameters.Add(dpCommentID);

                    DbParameter dpParentID = provider.CreateParameter();
                    dpParentID.ParameterName = parmPrefix + "parentid";
                    dpParentID.Value = comment.ParentId.ToString();
                    cmd.Parameters.Add(dpParentID);

                    DbParameter dpParentType = provider.CreateParameter();
                    dpParentType.ParameterName = parmPrefix + "type";
                    dpParentType.Value = type;
                    cmd.Parameters.Add(dpParentType);

                    DbParameter dpCommentDate = provider.CreateParameter();
                    dpCommentDate.ParameterName = parmPrefix + "date";
                    dpCommentDate.Value = comment.DateCreated.AddHours(-TrainSettings.Instance.Timezone);
                    cmd.Parameters.Add(dpCommentDate);

                    DbParameter dpAuthor = provider.CreateParameter();
                    dpAuthor.ParameterName = parmPrefix + "author";
                    dpAuthor.Value = comment.Author;
                    cmd.Parameters.Add(dpAuthor);

                    DbParameter dpCount = provider.CreateParameter();
                    dpCount.ParameterName = parmPrefix + "count";
                    dpCount.Value = comment.Count;
                    cmd.Parameters.Add(dpCount);

                    DbParameter dpSex = provider.CreateParameter();
                    dpSex.ParameterName = parmPrefix + "sex";
                    dpSex.Value = comment.Sex;
                    cmd.Parameters.Add(dpSex);

                    DbParameter dpPhone = provider.CreateParameter();
                    dpPhone.ParameterName = parmPrefix + "phone";
                    dpPhone.Value = comment.Phone;
                    cmd.Parameters.Add(dpPhone);

                    DbParameter dpMobile = provider.CreateParameter();
                    dpMobile.ParameterName = parmPrefix + "mobile";
                    dpMobile.Value = comment.Mobile;
                    cmd.Parameters.Add(dpMobile);

                    DbParameter dpEmail = provider.CreateParameter();
                    dpEmail.ParameterName = parmPrefix + "email";
                    dpEmail.Value = comment.Email ?? "";
                    cmd.Parameters.Add(dpEmail);

                    DbParameter dpCompany = provider.CreateParameter();
                    dpCompany.ParameterName = parmPrefix + "company";
                    if (comment.Company == null)
                        dpCompany.Value = string.Empty;
                    else
                        dpCompany.Value = comment.Company.ToString();
                    cmd.Parameters.Add(dpCompany);

                    DbParameter dpQQ_msn = provider.CreateParameter();
                    dpQQ_msn.ParameterName = parmPrefix + "qq_msn";
                    if (comment.QQ_msn == null)
                        dpQQ_msn.Value = string.Empty;
                    else
                        dpQQ_msn.Value = comment.QQ_msn.ToString();
                    cmd.Parameters.Add(dpQQ_msn);

                    DbParameter dpContent = provider.CreateParameter();
                    dpContent.ParameterName = parmPrefix + "comment";
                    dpContent.Value = comment.Content;
                    cmd.Parameters.Add(dpContent);

                    DbParameter dpIsApproved = provider.CreateParameter();
                    dpIsApproved.ParameterName = parmPrefix + "isapproved";
                    dpIsApproved.Value = comment.IsApproved;
                    cmd.Parameters.Add(dpIsApproved);

                    DbParameter dpModeratedBy = provider.CreateParameter();
                    dpModeratedBy.ParameterName = parmPrefix + "moderatedby";
                    dpModeratedBy.Value = comment.ModeratedBy ?? string.Empty;
                    cmd.Parameters.Add(dpModeratedBy);

                    DbParameter dpCountry = provider.CreateParameter();
                    dpCountry.ParameterName = parmPrefix + "country";
                    dpCountry.Value = comment.Country ?? string.Empty;
                    cmd.Parameters.Add(dpCountry);

                    DbParameter dpIP = provider.CreateParameter();
                    dpIP.ParameterName = parmPrefix + "ip";
                    dpIP.Value = comment.IP ?? string.Empty;
                    cmd.Parameters.Add(dpIP);

                    cmd.ExecuteNonQuery();
                }
            }
        }
 internal static DbParameter CreateParameter(DbProviderFactory factory)
 {
     return factory.CreateParameter();
 }
예제 #19
0
        private void UpdateCategories(Post post, DbConnection conn, DbProviderFactory provider)
        {
            string sqlQuery = "DELETE FROM " + tablePrefix + "PostCategory WHERE PostID = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = post.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (Category cat in post.Categories)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + "PostCategory (PostID, CategoryID) " +
                        "VALUES (" + parmPrefix + "id, " + parmPrefix + "cat)";
                    cmd.Parameters.Clear();
                    DbParameter dpPostID = provider.CreateParameter();
                    dpPostID.ParameterName = parmPrefix + "id";
                    dpPostID.Value = post.Id.ToString();
                    cmd.Parameters.Add(dpPostID);
                    DbParameter dpCat = provider.CreateParameter();
                    dpCat.ParameterName = parmPrefix + "cat";
                    dpCat.Value = cat.Id.ToString();
                    cmd.Parameters.Add(dpCat);

                    cmd.ExecuteNonQuery();
                }
            }
        }
예제 #20
0
        private void addBlogRollParametersToCommand(BlogRollItem blogRollItem, DbProviderFactory provider, DbCommand cmd)
        {
            DbParameter dpID = provider.CreateParameter();
            dpID.ParameterName = parmPrefix + "BlogRollId";
            dpID.Value = blogRollItem.Id.ToString();
            cmd.Parameters.Add(dpID);

            DbParameter dpTitle = provider.CreateParameter();
            dpTitle.ParameterName = parmPrefix + "Title";
            dpTitle.Value = blogRollItem.Title;
            cmd.Parameters.Add(dpTitle);

            DbParameter dpDesc = provider.CreateParameter();
            dpDesc.ParameterName = parmPrefix + "Description";
            dpDesc.Value = blogRollItem.Description;
            cmd.Parameters.Add(dpDesc);

            DbParameter dpBlogUrl = provider.CreateParameter();
            dpBlogUrl.ParameterName = "BlogUrl";
            dpBlogUrl.Value = blogRollItem.BlogUrl != null ? (object)blogRollItem.BlogUrl.ToString() : DBNull.Value;
            cmd.Parameters.Add(dpBlogUrl);

            DbParameter dpFeedUrl = provider.CreateParameter();
            dpFeedUrl.ParameterName = "FeedUrl";
            dpFeedUrl.Value = blogRollItem.FeedUrl != null ? (object)blogRollItem.FeedUrl.ToString() : DBNull.Value;
            cmd.Parameters.Add(dpFeedUrl);

            DbParameter dpXfn = provider.CreateParameter();
            dpXfn.ParameterName = "Xfn";
            dpXfn.Value = blogRollItem.Xfn;
            cmd.Parameters.Add(dpXfn);

            DbParameter dpSortIndex = provider.CreateParameter();
            dpSortIndex.ParameterName = "SortIndex";
            dpSortIndex.Value = blogRollItem.SortIndex;
            cmd.Parameters.Add(dpSortIndex);
        }
 private static CodeExpression BuildNewSqlCeParameterStatement(DesignParameter parameter, DbProviderFactory factory)
 {
     SqlDbType type = SqlDbType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             type = (SqlDbType) Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     Type componentType = null;
     object component = factory.CreateParameter();
     if (component != null)
     {
         componentType = component.GetType();
     }
     if (!flag && (component != null))
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(componentType);
         if (properties != null)
         {
             PropertyDescriptor descriptor = properties["DbType"];
             if (descriptor != null)
             {
                 descriptor.SetValue(component, parameter.DbType);
                 type = (SqlDbType) descriptor.GetValue(component);
             }
         }
     }
     return NewParameter(parameter, componentType, typeof(SqlDbType), type.ToString());
 }
예제 #22
0
        private static ProviderInfo GetProviderInfo(DbProviderFactory dbProviderFactory)
        {
            Debug.Assert(dbProviderFactory != null);

            var parameter = dbProviderFactory.CreateParameter();
            if (parameter == null)
                throw new NotSupportedException();

            var specificTypeProperties =
                from property in parameter.GetType().GetProperties()
                let attribute = (DbProviderSpecificTypePropertyAttribute)Attribute.GetCustomAttribute(property, typeof(DbProviderSpecificTypePropertyAttribute), false)
                where attribute != null
                   && attribute.IsProviderSpecificTypeProperty
                select property;

            var specificTypeProperty = specificTypeProperties.Single();
            var specificType = specificTypeProperty.PropertyType;
            var clobDbType = GetEnumValueOfAny(specificType, "NClob");
            var refCursorDbType = GetEnumValueOfAny(specificType, "Cursor", "RefCursor");

            return new ProviderInfo(specificTypeProperty, clobDbType, refCursorDbType);
        }
예제 #23
0
        public DataTable getDataTable(String queryString, params dynamic[] args)
        {
            DataTable table = null;

            queryString = queryString.Replace("\r", " ").Replace("\n", "").Replace("\t", " ");
            Console.WriteLine("Select cmd: " + queryString);
            string lib = GetProviderFactoryLib(providerName);

            System.Data.Common.DbProviderFactory provider = RegisterProvider(providerName);
            DbConnection con = provider.CreateConnection();

            con.ConnectionString = BuildConnectionString(providerName, this.dbName);
            dataSet = new DataSet();
            if (dataAdapter == null)
            {
                if (this.tableName == null)
                {
                    SetTableName(queryString);
                }

                tableStruct = RetrieveTableStructure(this.tableName);
                if (tableStruct.Columns.Count == 0)
                {
                    return(null);
                }
                dataAdapter = provider.CreateDataAdapter();
                dataAdapter.SelectCommand             = BuildSelectCommand(provider, con, queryString, args);;
                dataAdapter.DeleteCommand             = BuildDeleteCommand(provider, con);
                dataAdapter.UpdateCommand             = BuildUpdateCommand(provider, con);
                dataAdapter.InsertCommand             = BuildInsertCommand(provider, con);
                dataAdapter.AcceptChangesDuringFill   = true;
                dataAdapter.AcceptChangesDuringUpdate = true;
                dataAdapter.ContinueUpdateOnError     = false;
            }

            if (con.ConnectionString != dataAdapter.SelectCommand.Connection.ConnectionString)
            {
                dataAdapter.SelectCommand = BuildSelectCommand(provider, con, queryString, args);;
                dataAdapter.DeleteCommand = BuildDeleteCommand(provider, con);
                dataAdapter.UpdateCommand = BuildUpdateCommand(provider, con);
                dataAdapter.InsertCommand = BuildInsertCommand(provider, con);
            }
            if (args.Length > 0)
            {
                dataAdapter.SelectCommand.Parameters.Clear();
                foreach (var param in args)
                {
                    DbParameter par = provider.CreateParameter();
                    par.Direction     = ParameterDirection.Input;
                    par.ParameterName = param.Name;
                    par.Value         = param.Value;
                    dataAdapter.SelectCommand.Parameters.Add(par);
                }
            }
            try
            {
                con.Open();
                //BuildTableMapping(dataAdapter);
                dataAdapter.Fill(dataSet, this.tableName);
                table = dataSet.Tables[this.tableName];
                dataAdapter.MissingMappingAction = MissingMappingAction.Passthrough;
                if (identityColumn != null)
                {
                    if (table.Columns.Contains(identityColumn))
                    {
                        table.PrimaryKey = new DataColumn[] { table.Columns[identityColumn] };
                        table.Columns[identityColumn].AllowDBNull = true;
                    }
                    else
                    {
                        throw new Exception(String.Format("Tabela {0}, nu contine coloana Identity ={1}", tableName, identityColumn));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return(table);
        }
예제 #24
0
 /// <summary>
 /// 创建参数
 /// </summary>
 /// <returns></returns>
 public DbParameter CreateParameter()
 {
     return(dbFactory.CreateParameter());
 }
예제 #25
0
 public IDataParameter CreateParameter()
 {
     //return blank parameter of the correct type
     return(_frameworkProviderFactory.CreateParameter());
 }
예제 #26
0
        private void UpdateNotify(Post post, DbConnection conn, DbProviderFactory provider)
        {
            string sqlQuery = "DELETE FROM " + tablePrefix + "PostNotify WHERE PostID = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = post.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (string email in post.NotificationEmails)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + "PostNotify (PostID, NotifyAddress) " +
                        "VALUES (" + parmPrefix + "id, " + parmPrefix + "notify)";
                    cmd.Parameters.Clear();
                    DbParameter dpPostID = provider.CreateParameter();
                    dpPostID.ParameterName = parmPrefix + "id";
                    dpPostID.Value = post.Id.ToString();
                    cmd.Parameters.Add(dpPostID);
                    DbParameter dpNotify = provider.CreateParameter();
                    dpNotify.ParameterName = parmPrefix + "notify";
                    dpNotify.Value = email;
                    cmd.Parameters.Add(dpNotify);

                    cmd.ExecuteNonQuery();
                }
            }
        }
 public static PropertyInfo GetProviderTypeProperty(DbProviderFactory factory)
 {
     if (factory == null)
     {
         throw new ArgumentNullException("factory should not be null.");
     }
     if (providerData.UseCachedPropertyValue)
     {
         return providerData.ProviderTypeProperty;
     }
     providerData.UseCachedPropertyValue = true;
     foreach (PropertyInfo info in factory.CreateParameter().GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         if (info.PropertyType.IsEnum)
         {
             object[] customAttributes = info.GetCustomAttributes(typeof(DbProviderSpecificTypePropertyAttribute), true);
             if ((customAttributes.Length > 0) && ((DbProviderSpecificTypePropertyAttribute) customAttributes[0]).IsProviderSpecificTypeProperty)
             {
                 providerData.ProviderTypeProperty = info;
                 return info;
             }
         }
     }
     providerData.ProviderTypeProperty = null;
     return null;
 }
        /// <summary>
        /// The update categories.
        /// </summary>
        /// <param name="post">
        /// The post to update.
        /// </param>
        /// <param name="conn">
        /// The connection.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private void UpdateCategories(Post post, DbConnection conn, DbProviderFactory provider)
        {
            var sqlQuery = string.Format("DELETE FROM {0}PostCategory WHERE PostID = {1}id", this.tablePrefix, this.parmPrefix);
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                var id = provider.CreateParameter();
                if (id != null)
                {
                    id.ParameterName = string.Format("{0}id", this.parmPrefix);
                    id.Value = post.Id.ToString();
                    cmd.Parameters.Add(id);
                }

                cmd.ExecuteNonQuery();

                foreach (var cat in post.Categories)
                {
                    cmd.CommandText = string.Format("INSERT INTO {0}PostCategory (PostID, CategoryID) VALUES ({1}id, {2}cat)", this.tablePrefix, this.parmPrefix, this.parmPrefix);
                    cmd.Parameters.Clear();
                    var postId = provider.CreateParameter();
                    if (postId != null)
                    {
                        postId.ParameterName = string.Format("{0}id", this.parmPrefix);
                        postId.Value = post.Id.ToString();
                        cmd.Parameters.Add(postId);
                    }

                    var category = provider.CreateParameter();
                    if (category != null)
                    {
                        category.ParameterName = string.Format("{0}cat", this.parmPrefix);
                        category.Value = cat.Id.ToString();
                        cmd.Parameters.Add(category);
                    }

                    cmd.ExecuteNonQuery();
                }
            }
        }
        /// <summary>
        /// The update comments.
        /// </summary>
        /// <param name="post">
        /// The post to update.
        /// </param>
        /// <param name="conn">
        /// The connection.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private void UpdateComments(Post post, DbConnection conn, DbProviderFactory provider)
        {
            var sqlQuery = string.Format("DELETE FROM {0}PostComment WHERE PostID = {1}id", this.tablePrefix, this.parmPrefix);
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                var id = provider.CreateParameter();
                if (id != null)
                {
                    id.ParameterName = string.Format("{0}id", this.parmPrefix);
                    id.Value = post.Id.ToString();
                    cmd.Parameters.Add(id);
                }

                cmd.ExecuteNonQuery();

                foreach (var comment in post.Comments)
                {
                    sqlQuery = string.Format("INSERT INTO {0}PostComment (PostCommentID, ParentCommentID, PostID, CommentDate, Author, Email, Website, Comment, Country, Ip, IsApproved, ModeratedBy, Avatar, IsSpam, IsDeleted) VALUES (@postcommentid, @parentid, @id, @date, @author, @email, @website, @comment, @country, @ip, @isapproved, @moderatedby, @avatar, @isspam, @isdeleted)", this.tablePrefix);
                    if (this.parmPrefix != "@")
                    {
                        sqlQuery = sqlQuery.Replace("@", this.parmPrefix);
                    }

                    cmd.CommandText = sqlQuery;
                    cmd.Parameters.Clear();
                    var commentId = provider.CreateParameter();
                    if (commentId != null)
                    {
                        commentId.ParameterName = string.Format("{0}postcommentid", this.parmPrefix);
                        commentId.Value = comment.Id.ToString();
                        cmd.Parameters.Add(commentId);
                    }

                    var parentId = provider.CreateParameter();
                    if (parentId != null)
                    {
                        parentId.ParameterName = string.Format("{0}parentid", this.parmPrefix);
                        parentId.Value = comment.ParentId.ToString();
                        cmd.Parameters.Add(parentId);
                    }

                    var postId = provider.CreateParameter();
                    if (postId != null)
                    {
                        postId.ParameterName = string.Format("{0}id", this.parmPrefix);
                        postId.Value = post.Id.ToString();
                        cmd.Parameters.Add(postId);
                    }

                    var dpCommentDate = provider.CreateParameter();
                    dpCommentDate.ParameterName = this.parmPrefix + "date";
                    dpCommentDate.Value = comment.DateCreated.AddHours(-BlogSettings.Instance.Timezone);
                    cmd.Parameters.Add(dpCommentDate);

                    var dpAuthor = provider.CreateParameter();
                    dpAuthor.ParameterName = this.parmPrefix + "author";
                    dpAuthor.Value = comment.Author;
                    cmd.Parameters.Add(dpAuthor);

                    var dpEmail = provider.CreateParameter();
                    dpEmail.ParameterName = this.parmPrefix + "email";
                    dpEmail.Value = comment.Email ?? string.Empty;
                    cmd.Parameters.Add(dpEmail);

                    var dpWebsite = provider.CreateParameter();
                    if (dpWebsite != null)
                    {
                        dpWebsite.ParameterName = string.Format("{0}website", this.parmPrefix);
                        dpWebsite.Value = comment.Website == null ? string.Empty : comment.Website.ToString();
                        cmd.Parameters.Add(dpWebsite);
                    }

                    var dpContent = provider.CreateParameter();
                    dpContent.ParameterName = this.parmPrefix + "comment";
                    dpContent.Value = comment.Content;
                    cmd.Parameters.Add(dpContent);

                    var dpCountry = provider.CreateParameter();
                    dpCountry.ParameterName = this.parmPrefix + "country";
                    dpCountry.Value = comment.Country ?? string.Empty;
                    cmd.Parameters.Add(dpCountry);

                    var dpIP = provider.CreateParameter();
                    dpIP.ParameterName = this.parmPrefix + "ip";
                    dpIP.Value = comment.IP ?? string.Empty;
                    cmd.Parameters.Add(dpIP);

                    var dpIsApproved = provider.CreateParameter();
                    dpIsApproved.ParameterName = this.parmPrefix + "isapproved";
                    dpIsApproved.Value = comment.IsApproved;
                    cmd.Parameters.Add(dpIsApproved);

                    var dpModeratedBy = provider.CreateParameter();
                    dpModeratedBy.ParameterName = this.parmPrefix + "moderatedby";
                    dpModeratedBy.Value = comment.ModeratedBy ?? string.Empty;
                    cmd.Parameters.Add(dpModeratedBy);

                    var dpAvatar = provider.CreateParameter();
                    dpAvatar.ParameterName = this.parmPrefix + "avatar";
                    dpAvatar.Value = comment.Avatar ?? string.Empty;
                    cmd.Parameters.Add(dpAvatar);

                    var dpIsSpam = provider.CreateParameter();
                    dpIsSpam.ParameterName = this.parmPrefix + "isspam";
                    dpIsSpam.Value = comment.IsSpam;
                    cmd.Parameters.Add(dpIsSpam);

                    var dpIsDeleted = provider.CreateParameter();
                    dpIsDeleted.ParameterName = this.parmPrefix + "isdeleted";
                    dpIsDeleted.Value = comment.IsDeleted;
                    cmd.Parameters.Add(dpIsDeleted);

                    cmd.ExecuteNonQuery();
                }
            }
        }
        /// <summary>
        /// The update notify.
        /// </summary>
        /// <param name="post">
        /// The post to update.
        /// </param>
        /// <param name="conn">
        /// The connection.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private void UpdateNotify(Post post, DbConnection conn, DbProviderFactory provider)
        {
            var sqlQuery = string.Format("DELETE FROM {0}PostNotify WHERE PostID = {1}id", this.tablePrefix, this.parmPrefix);
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                var id = provider.CreateParameter();
                if (id != null)
                {
                    id.ParameterName = string.Format("{0}id", this.parmPrefix);
                    id.Value = post.Id.ToString();
                    cmd.Parameters.Add(id);
                }

                cmd.ExecuteNonQuery();

                foreach (var email in post.NotificationEmails)
                {
                    cmd.CommandText = string.Format("INSERT INTO {0}PostNotify (PostID, NotifyAddress) VALUES ({1}id, {2}notify)", this.tablePrefix, this.parmPrefix, this.parmPrefix);
                    cmd.Parameters.Clear();
                    var postId = provider.CreateParameter();
                    if (postId != null)
                    {
                        postId.ParameterName = string.Format("{0}id", this.parmPrefix);
                        postId.Value = post.Id.ToString();
                        cmd.Parameters.Add(postId);
                    }
                    var notify = provider.CreateParameter();
                    if (notify != null)
                    {
                        notify.ParameterName = string.Format("{0}notify", this.parmPrefix);
                        notify.Value = email;
                        cmd.Parameters.Add(notify);
                    }

                    cmd.ExecuteNonQuery();
                }
            }
        }
예제 #31
0
        private void addReferrersParametersToCommand(Referrer referrer, DbProviderFactory provider, DbCommand cmd)
        {
            DbParameter dpId = provider.CreateParameter();
            dpId.ParameterName = "ReferrerId";
            dpId.Value = referrer.Id.ToString();
            cmd.Parameters.Add(dpId);

            DbParameter dpDay = provider.CreateParameter();
            dpDay.ParameterName = parmPrefix + "ReferralDay";
            dpDay.Value = referrer.Day;
            cmd.Parameters.Add(dpDay);

            DbParameter dpReferrer = provider.CreateParameter();
            dpReferrer.ParameterName = parmPrefix + "ReferrerUrl";
            dpReferrer.Value = referrer.ReferrerUrl != null ? (object)referrer.ReferrerUrl.ToString() : DBNull.Value;
            cmd.Parameters.Add(dpReferrer);

            DbParameter dpCount = provider.CreateParameter();
            dpCount.ParameterName = parmPrefix + "ReferralCount";
            dpCount.Value = referrer.Count;
            cmd.Parameters.Add(dpCount);

            DbParameter dpUrl = provider.CreateParameter();
            dpUrl.ParameterName = "Url";
            dpUrl.Value = referrer.Url != null ? (object)referrer.Url.ToString() : DBNull.Value;
            cmd.Parameters.Add(dpUrl);

            DbParameter dpIsSpam = provider.CreateParameter();
            dpIsSpam.ParameterName = "IsSpam";
            dpIsSpam.Value = referrer.PossibleSpam;
            cmd.Parameters.Add(dpIsSpam);
        }
        /// <summary>
        /// The update tags.
        /// </summary>
        /// <param name="post">
        /// The post to update.
        /// </param>
        /// <param name="conn">
        /// The connection.
        /// </param>
        /// <param name="provider">
        /// The provider.
        /// </param>
        private void UpdateTags(Post post, DbConnection conn, DbProviderFactory provider)
        {
            var sqlQuery = string.Format("DELETE FROM {0}PostTag WHERE PostID = {1}id", this.tablePrefix, this.parmPrefix);
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                var id = provider.CreateParameter();
                if (id != null)
                {
                    id.ParameterName = string.Format("{0}id", this.parmPrefix);
                    id.Value = post.Id.ToString();
                    cmd.Parameters.Add(id);
                }

                cmd.ExecuteNonQuery();

                foreach (var tag in post.Tags)
                {
                    cmd.CommandText = string.Format("INSERT INTO {0}PostTag (PostID, Tag) VALUES ({1}id, {2}tag)", this.tablePrefix, this.parmPrefix, this.parmPrefix);
                    cmd.Parameters.Clear();
                    var postId = provider.CreateParameter();
                    if (postId != null)
                    {
                        postId.ParameterName = string.Format("{0}id", this.parmPrefix);
                        postId.Value = post.Id.ToString();
                        cmd.Parameters.Add(postId);
                    }

                    var tag2 = provider.CreateParameter();
                    if (tag2 != null)
                    {
                        tag2.ParameterName = string.Format("{0}tag", this.parmPrefix);
                        tag2.Value = tag;
                        cmd.Parameters.Add(tag2);
                    }

                    cmd.ExecuteNonQuery();
                }
            }
        }
예제 #33
0
        private void UpdateComments(Post post, DbConnection conn, DbProviderFactory provider)
        {
            string sqlQuery = "DELETE FROM " + tablePrefix + "PostComment WHERE PostID = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = post.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (Comment comment in post.Comments)
                {
                    sqlQuery = "INSERT INTO " + tablePrefix + "PostComment (PostCommentID, ParentCommentID, PostID, CommentDate, Author, Email, Website, Comment, Country, Ip, IsApproved, ModeratedBy, Avatar) " +
                                        "VALUES (@postcommentid, @parentid, @id, @date, @author, @email, @website, @comment, @country, @ip, @isapproved, @moderatedby, @avatar)";
                    if (parmPrefix != "@")
                        sqlQuery = sqlQuery.Replace("@", parmPrefix);
                    cmd.CommandText = sqlQuery;
                    cmd.Parameters.Clear();
                    DbParameter dpCommentID = provider.CreateParameter();
                    dpCommentID.ParameterName = parmPrefix + "postcommentid";
                    dpCommentID.Value = comment.Id.ToString();
                    cmd.Parameters.Add(dpCommentID);

                    DbParameter dpParentID = provider.CreateParameter();
                    dpParentID.ParameterName = parmPrefix + "parentid";
                    dpParentID.Value = comment.ParentId.ToString();
                    cmd.Parameters.Add(dpParentID);

                    DbParameter dpPostID = provider.CreateParameter();
                    dpPostID.ParameterName = parmPrefix + "id";
                    dpPostID.Value = post.Id.ToString();
                    cmd.Parameters.Add(dpPostID);

                    DbParameter dpCommentDate = provider.CreateParameter();
                    dpCommentDate.ParameterName = parmPrefix + "date";
                    dpCommentDate.Value = comment.DateCreated.AddHours(-BlogSettings.Instance.Timezone);
                    cmd.Parameters.Add(dpCommentDate);

                    DbParameter dpAuthor = provider.CreateParameter();
                    dpAuthor.ParameterName = parmPrefix + "author";
                    dpAuthor.Value = comment.Author;
                    cmd.Parameters.Add(dpAuthor);

                    DbParameter dpEmail = provider.CreateParameter();
                    dpEmail.ParameterName = parmPrefix + "email";
                    dpEmail.Value = comment.Email ?? "";
                    cmd.Parameters.Add(dpEmail);

                    DbParameter dpWebsite = provider.CreateParameter();
                    dpWebsite.ParameterName = parmPrefix + "website";
                    if (comment.Website == null)
                        dpWebsite.Value = string.Empty;
                    else
                        dpWebsite.Value = comment.Website.ToString();
                    cmd.Parameters.Add(dpWebsite);

                    DbParameter dpContent = provider.CreateParameter();
                    dpContent.ParameterName = parmPrefix + "comment";
                    dpContent.Value = comment.Content;
                    cmd.Parameters.Add(dpContent);

                    DbParameter dpCountry = provider.CreateParameter();
                    dpCountry.ParameterName = parmPrefix + "country";
                    dpCountry.Value = comment.Country ?? string.Empty;
                    cmd.Parameters.Add(dpCountry);

                    DbParameter dpIP = provider.CreateParameter();
                    dpIP.ParameterName = parmPrefix + "ip";
                    dpIP.Value = comment.IP ?? string.Empty;
                    cmd.Parameters.Add(dpIP);

                    DbParameter dpIsApproved = provider.CreateParameter();
                    dpIsApproved.ParameterName = parmPrefix + "isapproved";
                    dpIsApproved.Value = comment.IsApproved;
                    cmd.Parameters.Add(dpIsApproved);

                    DbParameter dpModeratedBy = provider.CreateParameter();
                    dpModeratedBy.ParameterName = parmPrefix + "moderatedby";
                    dpModeratedBy.Value = comment.ModeratedBy ?? string.Empty;
                    cmd.Parameters.Add(dpModeratedBy);

                    DbParameter dpAvatar = provider.CreateParameter();
                    dpAvatar.ParameterName = parmPrefix + "avatar";
                    dpAvatar.Value = comment.Avatar ?? string.Empty;
                    cmd.Parameters.Add(dpAvatar);

                    cmd.ExecuteNonQuery();
                }
            }
        }
 public IDataParameter CreateParameter()
 {
     return(m_innerFactory.CreateParameter());
 }
예제 #35
0
        private void UpdateTags(Post post, DbConnection conn, DbProviderFactory provider)
        {
            string sqlQuery = "DELETE FROM " + tablePrefix + "PostTag WHERE PostID = " + parmPrefix + "id";
            using (DbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = sqlQuery;
                cmd.CommandType = CommandType.Text;
                DbParameter dpID = provider.CreateParameter();
                dpID.ParameterName = parmPrefix + "id";
                dpID.Value = post.Id.ToString();
                cmd.Parameters.Add(dpID);
                cmd.ExecuteNonQuery();

                foreach (string tag in post.Tags)
                {
                    cmd.CommandText = "INSERT INTO " + tablePrefix + "PostTag (PostID, Tag) " +
                        "VALUES (" + parmPrefix + "id, " + parmPrefix + "tag)";
                    cmd.Parameters.Clear();
                    DbParameter dpPostID = provider.CreateParameter();
                    dpPostID.ParameterName = parmPrefix + "id";
                    dpPostID.Value = post.Id.ToString();
                    cmd.Parameters.Add(dpPostID);
                    DbParameter dpTag = provider.CreateParameter();
                    dpTag.ParameterName = parmPrefix + "tag";
                    dpTag.Value = tag;
                    cmd.Parameters.Add(dpTag);

                    cmd.ExecuteNonQuery();
                }
            }
        }
예제 #36
0
        private static void AddParameter(this DbCommand comm, DbProviderFactory factory, string parameterName,
            DbType type, object value)
        {
            if (parameterName == null)
            {
                throw new ArgumentNullException("parameterName");
            }
            DbParameter param = factory.CreateParameter();
            if (param == null) return;
            param.DbType = type;
            param.ParameterName = parameterName;

            param.Value = value ?? DBNull.Value;

            comm.Parameters.Add(param);
        }