【发布时间】:2012-02-23 16:58:45
【问题描述】:
我有这段代码(如下),我收到以下错误:
没有为一个或多个参数指定值
但是当它再次运行时,'RateCenterName'、'QuantityThreshold'、'RateCenterID' 的值会显示更新,但'Province' 的值不会更新
代码:
string updateSql = "UPDATE RateCenters SET RateCenterName = ?, Province=?, QuantityThreshold = ?" + " WHERE 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
//OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ToString());
OleDbConnection conn = new OleDbConnection(@"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");
OleDbCommand cmd = null;
try
{
cmd = new OleDbCommand(updateSql, conn);
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.ToUInt32(quantityThreshold.Text);
cmd.Parameters.Add("@RateCenterID", OleDbType.Integer).Value = Convert.ToInt32(ratecenterid.Text);
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
//GridView1.EditIndex = -1; //refreshing
//GridView1.DataBind();
}
catch (OleDbException ex)
{
throw (ex);
}
finally
{
conn.Close();
conn.Dispose();
}
}
谁能看出问题所在?
版主编辑:
他解决了问题,但他的解决方案深入其中一个评论线程:
我明白了,我删除了 Row 更新事件并尝试了一次 再次不添加该事件。
我认为他的意思是:他将此代码从 RowUpdating 事件处理程序中取出并放在其他地方。
【问题讨论】:
-
at 符号是参数名称的一部分。
-
@500-InternalServerError 我改了,还是报错
-
请编辑您的问题,以便我们看到您的代码的最新版本(每个
@或?和WHERE之前的空格)。 -
@egrunin:我已经编辑到更新代码了!!
-
你仍然省略了
WHERE之前的空格。
标签: asp.net ms-access gridview