本文介绍了没有为一个或多个必需参数给出值EXCEPTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,
它引发错误:没有为一个或多个必需参数提供值
但是这些字段会在更新事件中更新
I have the following code,
It throws an error: No value given for one or more required parameters
but the fields are updated in the update event
string updateSql = "UPDATE RateCenters SET RateCenterName = @RateCenterName, Province = @Province, QuantityThreshold = @QuantityThreshold" + " WHERE RateCenterID= @RateCenterID";
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
DropDownList ddl = (DropDownList)row.FindControl("DropDownList2"); // assigning the dropdownlist item to ''ddl''
TextBox rateCenterName = (TextBox)row.FindControl("txtRateCenterName"); // assigning textbox input item
TextBox quantityThreshold = (TextBox)row.FindControl("txtQuantityThreshold"); // assigning textbox input item
Label ratecenterid = (Label)row.FindControl("Label1"); // assigning the label value
string scon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\arjun.giridhar\my documents\visual studio 2010\Projects\BillingApplicationNew\BillingApplicationNew\App_Data\db1.mdb;Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(scon);
try
{
OleDbCommand cmd = new OleDbCommand(updateSql, conn);
cmd.CommandText = updateSql;
cmd.Parameters.Add("@RateCenterName", OleDbType.VarChar).Value = rateCenterName.Text;
cmd.Parameters.Add("@Province", OleDbType.VarChar).Value = ddl.SelectedItem.Text;
cmd.Parameters.Add("@QuantityThreshold", OleDbType.Integer).Value = Convert.ToInt32(quantityThreshold.Text);
cmd.Parameters.Add("@RateCenterID", OleDbType.Integer).Value = Convert.ToInt32(ratecenterid.Text);
conn.Open();
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1; //refreshing
GridView1.DataBind();
}
catch (OleDbException ex)
{
throw (ex);
}
finally
{
conn.Close();
conn.Dispose();
}
请检查代码,并帮助我解决此任务
问候,
Arjun
Kindly check the code and help me to sort out this task
Regards,
Arjun
推荐答案
cmd.Parameters.Add("RateCenterName", OleDbType.VarChar).Value = rateCenterName.Text;
干杯
Cheers
这篇关于没有为一个或多个必需参数给出值EXCEPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!