Reputation: 73
while passing value to stored procedure getting error
"Failed to convert parameter value from a String to a Boolean".
not getting point why i am getting this issue while my code is,
C# code is here ,
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);
Parameters that are passing are as follows,
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 define parameters are,
@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,
while column of table are ,
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
i have tried alot but cant remove error hopes to listen from you soon
Thanks
Upvotes: 0
Views: 1791
Reputation: 2602
your problem is here :
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;
You are setting the value of both parameters to the same object while they are of different Sqltypes. One is VarChar and the other is bit.
InvPro.proj_WCB can be either a String or a Boolean. In your code you are treating it as if it is both.
Upvotes: 1
Reputation: 1879
Convert the value of the variable InvPro.proj_WCB
to a boolean would be my guess.
Upvotes: 0