Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Gridview drop-down , +
I have a code below, this code updates the dropdownlist in the gridview. The database is in MS Access
I get the error: "Parameter @RateCenterName has no default value."
 

RateCenterID is the primary key
 

string updateSql = "UPDATE [RateCenters] " + "SET [RateCenterName] = @RateCenterName, [Province]= @Province, [QuantityThreshold] =@QuantityThreshold  " + "WHERE [RateCenterID]=@RateCenterID";
 

    string ratecenterID;
 

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {                    
            GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            DropDownList ddl = (DropDownList)row.FindControl("DropDownList2");
            TextBox rateCenterName = (TextBox)row.FindControl("TextBox1");
            TextBox quantityThreshold = (TextBox)row.FindControl("TextBox2");
 

            OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ToString());
            OleDbCommand cmd = null;
 

            try
            {
                conn.Open();
                cmd = new OleDbCommand(updateSql, conn);
                cmd.Parameters.Add("@RateCenterName", OleDbType.VarChar).Value = rateCenterName.Text;
                cmd.Parameters.Add("@Province", OleDbType.VarChar).Value = ddl.SelectedValue;
                cmd.Parameters.Add("@QuantityThreshold", OleDbType.VarChar).Value = quantityThreshold.Text;
 

                cmd.Connection = conn;
                cmd.ExecuteNonQuery();
 
                GridView1.EditIndex = -1;
                GridView1.DataBind();
            }
            catch (OleDbException ex)
            {
                throw (ex);
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }
 
Kindly help me to solve this issue.
 

Regards,
Arjun
Posted 22-Feb-12 1:08am
Edited 22-Feb-12 1:13am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try following when adding parameters
 
cmd.Parameters.Add(new OleDbParameter("@RateCenterName", rateCenterName.Text));
 
also you have to provide parameter @RateCenterID
  Permalink  
v2
Comments
Member 8265319 at 22-Feb-12 7:03am
   
Kashif Atiq: now I have added the RateCenterID

 
Label ratecenterid = (Label)row.FindControl("Label1");

 
cmd.Parameters.Add("@RateCenterID", OleDbType.Integer).Value = ratecenterid.Text;

Now the error is different,

"No value given for one or more parameter"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

 @RateCenterID is missing please add and try then
  Permalink  
Comments
Member 8265319 at 22-Feb-12 7:03am
   
@Sudip Saha: now I have added the RateCenterID

 
Label ratecenterid = (Label)row.FindControl("Label1");

 
cmd.Parameters.Add("@RateCenterID", OleDbType.Integer).Value = ratecenterid.Text;

Now the error is different,

"No value given for one or more parameter"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Guys now I have added the RateCenterID
 

Label ratecenterid = (Label)row.FindControl("Label1");
 

cmd.Parameters.Add("@RateCenterID", OleDbType.Integer).Value = ratecenterid.Text;
 
Now the error is different,
 
"No value given for one or more parameter"
  Permalink  
v2
Comments
kashif Atiq at 22-Feb-12 6:53am
   
in your code check if "RateCenterName" and "QuantityThreshold" empty then supply any default values for them
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think the problem could be that the name of parameter is mismatching in code and stored procedure/query. and the filed that is giving the error is set as NOT NULL. double check spellings to make sure this is not the case.
 
changing the table definition to accepts nulls could also do the trick but perhaps hat a bad idea design-wise(i don't know the business logic here)
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 22 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100