单击保存按钮时不存在从对象类型 System.Windows.Forms.DateTimePicker 到已知托管提供程序本机类型错误的映射

No mapping exists from object type System.Windows.Forms.DateTimePicker to a known managed provider native type error while clicking on save button

我已经将print_dec、print_srno、oneclick_sale、enable_tracking和not_for_sale声明为布尔数据类型并存储了真/假和位数据类型当我点击保存按钮时在数据库定义中声明它给了我错误 “不存在从对象类型 System.Windows.Forms.DateTimePicker 到已知托管提供程序本机类型的映射”。 这是我的代码

 private void savebtn_Click(object sender, EventArgs e)

        {//start of body of save btn

            get_checkbox();
            Connectionclass conect = new Connectionclass();//ceating object of connectionclass
            conect.myconnection();//calling my connection method through conect object
            try//try method
            {//start of body of try
                get_group();//calling get group method
                get_brand();//calling get brand method
                get_unit();//calling get_unit method
                SqlCommand cmd = new SqlCommand("save_product", conect.conn);//creating the object of sqlcommand
                cmd.CommandType = CommandType.StoredProcedure;//defining the command type as stored procedure
                cmd.Connection = conect.conn;//assigning cmd connection string
                cmd.Parameters.AddWithValue("@group_id", group_id);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@brand_id", brand_id);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@unit_id",unit_id);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@Item_code", itemcodetxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@product_name", Productnametxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@print_name", printnametxt);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@purchase_price", Purchasepricetxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@sale__price", salepricetxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@min_sale_price", Minsalepricetxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@M_R_P", MRPtxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@openoing_stock", Openingstocktxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@opening_stock_value", openingstockvaluetxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@sale_discount", salediscounttxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@Low_level_limit", lowlevellimittxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@product_type", Producttypecmb.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@product_description", productdescriptiontxt.Text);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@print_description",print_desc);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@print_srno", print_srno);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@oneclick_sale", oneclick_sale);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@enable_tracking", enable_tracking);//passing text box vale to database column
                cmd.Parameters.AddWithValue("@not_for_sale", not);//passing text box vale to database column
                DialogResult dialogResult = MessageBox.Show("Do you want to add product", "group", MessageBoxButtons.YesNo, MessageBoxIcon.Information);//showing message to user
                if (dialogResult == DialogResult.Yes)//if statement
                //{//start of body of if 
                    //if (nametxt.Text == "")//if condition
                    //{//start of body of if
                        //MessageBox.Show("name is required");//this will show the message box to the user
                    //}//end of body of if
                    //else condition
                    {//start of body of if
                        cmd.ExecuteNonQuery();//executing the above queries
                        MessageBox.Show("group successfully added");//messaage box that will show that group is added
                        //cleargroup();//calling cleargroup method 
                    }//end of body of if
                //}//end of body of if
                
            }//end of body of try                                            
            catch (Exception ex)//exception method that will through exception
            {//start of body of catch
                MessageBox.Show(ex.Message, "saving error");//a message box that will show error if try not run
            }//end of body of catch
            finally
            {
                conect.conn.Close();//closing database connection
            }
        }//end of body of save btn

这是我的 sql 服务器代码

ALTER procedure [dbo].[save_product]
@group_id int,
@brand_id int,
@unit_id int,
@Item_code varchar(255),
@product_name varchar(255),
@print_name varchar(255),
@purchase_price float,
@sale__price float,
@min_sale_price float,
@M_R_P float,
@openoing_stock varchar(255),
@opening_stock_value float,
@sale_discount varchar(3),
@Low_level_limit varchar(255),
@product_type varchar(255),
@serial_no varchar(255),
@product_description varchar(255),
@print_description bit,
@print_srno bit,
@oneclick_sale bit,
@enable_tracking bit,
@not_for_sale bit
as
begin
insert into add_product (
group_id,
brand_id,
unit_id,
Item_code,
product_name,
print_name,
purchase_price,
sale__price,
min_sale_price,
M_R_P,
openoing_stock,
opening_stock_value,
sale_discount,
Low_level_limit,
product_type,
serial_no,
product_description,
print_description,
print_srno,
oneclick_sale,
enable_tracking,
not_for_sale
)
values
(
@group_id,
@brand_id ,
@unit_id ,
@Item_code ,
@product_name ,
@print_name ,
@purchase_price ,
@sale__price ,
@min_sale_price ,
@M_R_P ,
@openoing_stock ,
@opening_stock_value ,
@sale_discount ,
@Low_level_limit ,
@product_type ,
@serial_no ,
@product_description,
@print_description ,
@print_srno ,
@oneclick_sale,
@enable_tracking ,
@not_for_sale 
)

end

[这是我的异常错误图片][1] [1]: https://i.stack.imgur.com/oAufM.png

出现此异常是因为您传递的是实际的文本框对象,而不是其值(在本例中为文本 属性)。

例如,而不是:

cmd.Parameters.AddWithValue("@print_name", printnametxt);

写入:

cmd.Parameters.AddWithValue("@print_name", printnametxt.Text);