Gridview更新(不起作用) [英] Gridview update(not functioning)
本文介绍了Gridview更新(不起作用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,并且在运行期间收到错误,提示为没有为一个或多个参数提供值"
I have this code and I get the error during the run as "No value given for one or more parameters"
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
// 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();
}
}
读取了值,但我希望它不会被存储在cmd.parameter语句中的@xxxxxx中
请帮助我
问候,Arjun
values are read but I hope it is not getting stored in @xxxxxx in cmd.parameter statement
kindly help me out
regards, Arjun
推荐答案
您正在使用oledbcommand不能使用的命名参数.您需要使用吗? char作为参数,当您在命令参数集合中添加参数时,您需要按正确的顺序添加它们,就像查询中有参数一样.
示例:
Hi,
You are using named parameters which is not possible with oledbcommand. You need to use ? char for parameters, and when you add parameters in command parameters collection you need to add them in proper order like you have parameters in your query...
Example:
string updateSql = "UPDATE RateCenters SET RateCenterName = ?, Province=
?, QuantityThreshold = ? WHERE RateCenterID= ?";
// ...
OleDbParameter p1 = new OleDbParameter();
OleDbParameter p2 = new OleDbParameter();
OleDbParameter p3 = new OleDbParameter();
OleDbParameter p4 = new OleDbParameter();
p1.Value = "RateCenterName ";
p2.Value = "Province";
p3.Value = "QuantityThreshold ";
p2.Value = "RateCenterID";
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
// ...
添加参数时,您需要按命令中的顺序对其进行添加...
该代码可能有错误,并且提供该代码只是为了显示我的意思...
While adding parameters you need to add them in order like they are in command...
The code maybe have errors and its provided just to show what I mean...
在下面的查询中使用:
Hi, use below query:
string updateSql = "UPDATE RateCenters SET RateCenterName = @RateCenterName, Province=
@Province, QuantityThreshold = @QuantityThreshold" + " WHERE RateCenterID= @RateCenterID";
这篇关于Gridview更新(不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文