没有为一个或多个必需参数给出值EXCEPTION [英] No value given for one or more required parameters EXCEPTION

查看:61
本文介绍了没有为一个或多个必需参数给出值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

推荐答案

从您的参数名称中删除"@",例如:

Remove the "@" from your parametername like :

cmd.Parameters.Add("RateCenterName", OleDbType.VarChar).Value = rateCenterName.Text;



干杯



Cheers


我明白了,我删除了Row更新事件,只是再次尝试了一次,而没有添加该事件.它解决了. Microsoft非常适合创建这些用户控件!
I got it, i removed the Row updating event and just tried it once again without adding that event. It worked out. Microsoft is great for creating those user controls!


这篇关于没有为一个或多个必需参数给出值EXCEPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆