将值传递给存储过程获取错误
"Failed to convert parameter value from a String to a Boolean".
在我的代码是
时,我没有明白为什么我会遇到这个问题C#代码在这里,
invProject.targetprojectId =Convert.ToInt32(this.txtOrderNumber.Text);
invProject.projects = this.txtProjectTitle.Text;
invProject.bridge_cost = Convert.ToDouble(this.txtBridgeCost.Text);
invProject.high_cost = Convert.ToDouble(this.txtHighwayCost.Text);
invProject.bridge_comp = this.ddlbridgeComplexity.SelectedValue.ToString();
invProject.hway_comp = this.ddlHighwayComplexity.SelectedValue.ToString();
invProject.project_type = this.ddlProjectType.SelectedValue.ToString();
invProject.proj_Owner = this.ddlProjectOwner.SelectedValue.ToString();
invProject.ind_Exp = Convert.ToInt32(this.chkIndividualExperience.Checked);
传递的参数如下,
SqlParameter projectid = cmd.Parameters.Add("@Target_Project_ID", SqlDbType.Int);
projectid.Value = InvPro.targetprojectId;
SqlParameter title = cmd.Parameters.Add("@Projects", SqlDbType.VarChar);
title.Value = InvPro.projects;
SqlParameter bridgecost = cmd.Parameters.Add("@Bridge_Cost", SqlDbType.Money);
bridgecost.Value = InvPro.bridge_cost;
SqlParameter highwaycost = cmd.Parameters.Add("@Hway_Cost", SqlDbType.Money);
highwaycost.Value = InvPro.high_cost;
SqlParameter bComplexity = cmd.Parameters.Add("@Bridge_Comp", SqlDbType.VarChar);
bComplexity.Value = InvPro.bridge_comp;
SqlParameter hComplexity = cmd.Parameters.Add("@Hway_Comp", SqlDbType.VarChar);
hComplexity.Value = InvPro.hway_comp;
SqlParameter cProjectOwner = cmd.Parameters.Add("@ProjectType", SqlDbType.VarChar);
cProjectOwner.Value = InvPro.project_type;
SqlParameter ProjectOwner = cmd.Parameters.Add("@Proj_Owner", SqlDbType.VarChar);
ProjectOwner.Value = InvPro.proj_Owner;
SqlParameter workclass = cmd.Parameters.Add("@Proj_WCB", SqlDbType.VarChar);
workclass.Value = InvPro.proj_WCB;
SqlParameter INdExp = cmd.Parameters.Add("@Ind_Exp", SqlDbType.Bit);
INdExp.Value = InvPro.proj_WCB;
SP定义参数是,
@Target_Project_ID int,
@Projects varchar(50),
@Bridge_Cost money,
@Hway_Cost money,
@Bridge_Comp nvarchar(50),
@Hway_Comp nvarchar(50),
@ProjectType nvarchar(50),
@Proj_Owner nvarchar(50),
@Proj_WCB nvarchar(50),
@Ind_Exp bit,
而表格的列是,
Target_Project_ID int
Projects nvarchar
Bridge_Cost money
Hway_Cost money
Bridge_Comp nvarchar
Hway_Comp nvarchar
Proj_WCB nvarchar
Proj_Owner nvarchar
Ind_Exp bit
我已经尝试了很多,但不能删除错误希望很快收到你的消息
由于
答案 0 :(得分:1)
你的问题在这里:
SqlParameter workclass = cmd.Parameters.Add("@Proj_WCB", SqlDbType.VarChar);
workclass.Value = InvPro.proj_WCB;
SqlParameter INdExp = cmd.Parameters.Add("@Ind_Exp", SqlDbType.Bit);
INdExp.Value = InvPro.proj_WCB;
您将两个参数的值设置为同一个对象,而它们具有不同的Sqltypes。一个是VarChar,另一个是bit。
InvPro.proj_WCB可以是String或Boolean。 在你的代码中,你将它视为两者兼而有之。
答案 1 :(得分:0)
将变量InvPro.proj_WCB
的值转换为布尔值将是我的猜测。