Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
             }


Kindly check the code and help me to sort out this task

Regards,
Arjun
Posted

Remove the "@" from your parametername like :

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


Cheers
 
Share this answer
 
Comments
ArjunBabu 24-Feb-12 10:02am    
@Estys: Still getting the same error
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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900