参数没有默认值 [英] Parameter has no default value

查看:134
本文介绍了参数没有默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面有一段代码,这段代码更新了gridview中的下拉列表。数据库在MS Access
中出现错误:参数@RateCenterName没有默认值



RateCenterID是主键

 字符串updateSql =UPDATE [RateCenters]+SET [RateCenterName] = @RateCenterName,[Province] = @省,[QuantityThreshold] = @ QuantityThreshold+WHERE [RateCenterID] = @ RateCenterID; 

字符串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;

尝试
{
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();
}
}

请帮我解决这个问题。



问候,

Arjun

解决方案您的查询需要四个参数( @RateCenterName @Province @ QuantityThreshold @RateCenterID ),但您只能传递三次。 code> @RateCenterID 缺失。


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

解决方案

Your query takes four parameters (@RateCenterName, @Province, @QuantityThreshold and @RateCenterID), but you're only passing three.

@RateCenterID is missing.

这篇关于参数没有默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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