Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code and I get the error during the run as "No value given for one or more parameters"

C#
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();
        }
    }


values are read but I hope it is not getting stored in @xxxxxx in cmd.parameter statement

kindly help me out

regards, Arjun
Posted
Updated 23-Feb-12 6:06am
Comments
ZurdoDev 23-Feb-12 12:27pm    
Just run a SQL trace and see what is happening.
ArjunBabu 23-Feb-12 12:37pm    
how do you do SQL trace in access?
Martin Arapovic 23-Feb-12 12:55pm    
I think you can't trace that in access! Not sure, but I think Its impossible...
Problem is with parameters... Check my answer...
ZurdoDev 23-Feb-12 13:50pm    
I did not realize it was access. But I do notice you are missing a space " " before your WHERE statement so that will mess it up.
Martin Arapovic 23-Feb-12 13:54pm    
Yes, you are right. I fixed that to in my example... :) Tnx...

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:
C#
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...
 
Share this answer
 
Comments
ArjunBabu 24-Feb-12 4:58am    
@Martin Arapovi: I tried your code, RateCenterName, Province, QuantityThreshold, RateCenterID are getting values but the p1, p2, p3, p4 in cmd.parameters are not getting the values...The error is the displayed as "no value given for one or more parameters"
Martin Arapovic 25-Feb-12 8:10am    
Hi, there is an error in my code, p4 parameter didn't have value assigned! I posted code as concept and you shoud review it before use...
Hi, use below query:

C#
string updateSql = "UPDATE RateCenters SET RateCenterName = @RateCenterName, Province=
@Province, QuantityThreshold = @QuantityThreshold" + " WHERE RateCenterID= @RateCenterID";
 
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