我是c#的新手。我有以下代码用于编辑gridview,它将参数放入存储过程但运行时出现上述错误。我试过没有快乐地解析参数。我出错的任何想法?
protected void PipelineSelection_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = PipelineSelection.Rows[e.RowIndex];
int CustID = Convert.ToChar(PipelineSelection.DataKeys[e.RowIndex].Values[0]);
string BlueCollar = (row.FindControl("BlueCollarUpdateTextBox") as TextBox).Text;
string WhiteCollar = (row.FindControl("WhiteCollarUpdateTextBox") as TextBox).Text;
string PipelineID = (row.FindControl("PipelineUpdateDropDown") as DropDownList).SelectedValue;
string IndSubSector = (row.FindControl("SectorUpdateDropDown") as DropDownList).SelectedValue;
string PublicSectorID = (row.FindControl("PublicUpdateDropDown") as DropDownList).SelectedValue;
string Branches = (row.FindControl("BranchesUpdateBox") as TextBox).Text;
string Depts = (row.FindControl("DeptsUpdateTextBox") as TextBox).Text;
string OrderMethodID = (row.FindControl("OrderMethodUpdateDropDown") as DropDownList).SelectedValue;
string DelRequirements = (row.FindControl("DelUpdateTextBox") as TextBox).Text;
string constr = ConfigurationManager.ConnectionStrings["CRMConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SelectCustomerDetails"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustID", CustID);
cmd.Parameters.AddWithValue("@BlueCollar", Int32.Parse(BlueCollar));
cmd.Parameters.AddWithValue("@WhiteCollar", Int32.Parse(WhiteCollar));
cmd.Parameters.AddWithValue("@PipelineID", Int32.Parse(PipelineID));
cmd.Parameters.AddWithValue("@IndSubSectorID", Int32.Parse(IndSubSector));
cmd.Parameters.AddWithValue("@PublicSectorID", Int32.Parse(PublicSectorID));
cmd.Parameters.AddWithValue("@Branches", Int32.Parse(Branches));
cmd.Parameters.AddWithValue("@Depts", Int32.Parse(Depts));
cmd.Parameters.AddWithValue("@OrderMethodID", Int32.Parse(OrderMethodID));
cmd.Parameters.AddWithValue("@DelRequirements", DelRequirements);
cmd.Parameters.AddWithValue("@Action", "UpPipe");
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
PipelineSelection.EditIndex = -1;
this.BindPipeline();
}
以下存储过程
if @Action = 'UpPipe'
Begin
Update CustomerDetails set
NoOfEmployeesBlueCollar = convert(int, @BlueCollar),
NoOfEmployeesWhiteCollar = convert(int, @WhiteCollar),
PipelineID = convert(int, @PipelineID),
IndSubSectorID = convert(int, @IndSubSectorID),
PublicPrivateSectorID = convert(int, @PublicSectorID),
NoOfBranches = convert(int, @Branches),
NoOfDepartments = convert(int, @Depts),
OrderMethodID = convert(int, @OrderMethodID),
DeliveryRequirements = @DelRequirements
where CustID = @CustID
End