动态增加SqlParameter[]中的元素,自己的记录

                sqlsp  =   " BlogArticle_Update " ;
                SqlParameter[] param 
=  {
                                        
new  SqlParameter( " Content " ,Content.Value),
                                    };
                
// 重构数组
                SqlParameter[] param2;
                
if  (IsDefineWeight  ==   " 1 " )
                {
                    
int  newNum  =  param.Length  +   1 ;
                    param2 
=  (SqlParameter[])Redim(param, newNum);
                    param2[newNum 
-   1 =   new  SqlParameter( " Weight " , weight.Text);
                }
                
else
                {
                    param2 
=  param;
                }

                DAL.dbsp.ExecuteNonQuery(sqlsp, param2);

自己的记录

         public   static  Array Redim(Array origArray, Int32 desiredsize)
        {
            
// 确定每个元素类 型    
            Type t  =  origArray.GetType().GetElementType();
            
// 创建一个含有期望元素个数的新数组  
            
// 新数组的类型必须匹配原数组的类型  
            Array newArray  =  Array.CreateInstance(t, desiredsize);
            
// 将原数组中的元素拷贝到新数组中  
            Array.Copy(origArray,  0 , newArray,  0 , Math.Min(origArray.Length, desiredsize));
            
return  newArray;
        }

 

你可能感兴趣的:(parameter)