首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问下为什么小弟我数据添加到数据库是成功的程序却显示添加失败

2012-03-19 
请教下为什么我数据添加到数据库是成功的程序却显示添加失败谢谢protectedvoidBtnOK_Click(objectsender,E

请教下为什么我数据添加到数据库是成功的程序却显示添加失败
谢谢     protected   void   BtnOK_Click(object   sender,   EventArgs   e)
        {
                Product   SingleProduct   =   new   Product();
                SingleProduct.P_ID=   TxtNumber.Text;
                SingleProduct.P_Color   =   TxtColor.Text;
                SingleProduct.P_Type   =   DropType.SelectedValue;
                SingleProduct.P_Price   =   TxtPrice.Text;
                SingleProduct.P_Show   =   RadShow.SelectedValue;
                SingleProduct.P_Sell   =   RadSell.SelectedValue;
                SingleProduct.P_Picture1   =   P_Picture1.Value;
                SingleProduct.P_Picture2   =   P_Picture2.Value;
                SingleProduct.P_Introduce=   TxtIntroduce.Text;
               
                if   (Product.AddProduct(SingleProduct))//这一段有问题不知道什么原因
                {
                        this.Label2.Text   =   "产品添加成功! ";
                }
                else
                {
                        this.Label2.Text   =   "产品添加失败! ";
                }
product.cs
public   class   Product    
{
        private   int   id;
        public   int   ID
        {
                get   {   return   this.id;   }
                set   {   this.id   =   value;   }
        }
        private   string   p_id;
        public   string   P_ID
        {
                get   {   return   this.p_id;   }
                set   {   this.p_id   =   value;   }
               
        }
        private   string   p_color;
        public   string   P_Color
        {
                get   {   return   this.p_color;   }
                set   {   this.p_color   =   value;   }
        }
        private   string   p_type;
        public   string   P_Type


        {
                get   {   return   this.p_type;   }
                set   {   this.p_type   =   value;   }
        }
     
        private   string   p_price;
        public   string   P_Price
        {
                get   {   return   this.p_price;   }
                set   {   this.p_price   =   value;   }
        }
        private   string   p_show;
        public   string   P_Show
        {
                get   {   return   this.p_show;   }
                set   {   this.p_show   =   value;   }
        }
        private   string   p_picture1;
        public   string   P_Picture1
        {
                get   {   return   this.p_picture1;   }
                set   {   this.p_picture1   =   value;   }
        }
        private   string   p_sell;
        public   string   P_Sell
        {
                get   {   return   this.p_sell;   }
                set   {   this.p_sell   =   value;   }
        }
        private   string   p_introduce;
        public   string   P_Introduce
        {
                get   {   return   this.p_introduce;   }
                set   {   this.p_introduce   =   value;   }
        }


        private   string   p_picture2;
        public   string   P_Picture2
        {
                get   {   return   this.p_picture2;   }
                set   {   this.p_picture2   =   value;   }
        }
        public   Product()
        {
                //
                //   TODO:   在此处添加构造函数逻辑
                //
        }
        public   Product(SqlDataReader   Dr)
        {
                this.p_id   =   Convert.ToString(Dr[ "   P_ID "]);
                this.p_color   =   Convert.ToString(Dr[ "P_Color "]);


                this.p_type   =   Convert.ToString(Dr[ "P_Type "]);
                this.p_price   =   Convert.ToString(Dr[ "P_Pice "]);
                this.p_show   =   Convert.ToString(Dr[ "P_Show "]);
                this.p_sell   =   Convert.ToString(Dr[ "P_Sell "]);
                this.p_picture1   =   Convert.ToString(Dr[ "P_Picture1 "]);
                this.p_picture2   =   Convert.ToString(Dr[ "P_Picture2 "]);
                this.p_introduce   =   Convert.ToString(Dr[ "P_Introduce "]);
             

        }
        public   static   bool   AddProduct(Product   SingleProduct)
        {
                bool   Flage   =   false;
                string   procname   =   "dbo.AddProduct ";
                SqlParameter[]   prams   ={
                                                            new   SqlParameter( "@TxtNumber ",SqlDbType.VarChar,50),
                                                            new   SqlParameter( "@TxtColor ",   SqlDbType.VarChar,   50),
                                                            new   SqlParameter( "@DropType ",   SqlDbType.VarChar,   50),
                                                            new   SqlParameter( "@TxtPice ",   SqlDbType.VarChar,50),
                                                            new   SqlParameter( "@RadShow ",   SqlDbType.VarChar,   50),
                                                            new   SqlParameter( "@RadSell ",     SqlDbType.VarChar,   50),
                                                            new   SqlParameter( "@P_Picture1 ",   SqlDbType.VarChar,   200),
                                                            new   SqlParameter( "@P_Picture2 ",   SqlDbType.VarChar,   200),


                                                            new   SqlParameter( "@TxtIntroduce ",   SqlDbType.VarChar,   200)
                                                           
               
               
                };
                prams[0].Value   =   SingleProduct.P_ID;
                prams[1].Value   =   SingleProduct.P_Color;
                prams[2].Value   =   SingleProduct.P_Type;
                prams[3].Value   =   SingleProduct.P_Price;
                prams[4].Value   =   SingleProduct.P_Show;
                prams[5].Value   =   SingleProduct.P_Sell;
                prams[6].Value   =   SingleProduct.P_Picture1;
                prams[7].Value   =   SingleProduct.P_Picture2;
                prams[8].Value   =   SingleProduct.P_Introduce;
                int   intResult   =   DataBase.RunExecute(procname,   prams);
                if   (intResult   >   0)
                {
                        Flage   =   true;
                }
                return   Flage;
        }
DataBase.cs这个没问题的.

[解决办法]
断点调试进去没有问题的话,就要怀疑dbo.AddProduct这个了。是否里面sql语句写错?

热点排行