简体   繁体   English

C#:“System.Web.UI.WebControls.Parameter”的未知构造函数“Parameter(String, TypeCode, Int)”

[英]C#: Unknown constructor 'Parameter(String, TypeCode, Int)' of 'System.Web.UI.WebControls.Parameter'

In my code behind I have the code below to execute an insert command.在我后面的代码中,我有下面的代码来执行插入命令。 Two of the parameter values are to be set when the user clicks a particular button.当用户单击特定按钮时,将设置两个参数值。 I broke it out this way because I'd like to reuse the SqlDataSource .我这样打破它是因为我想重用SqlDataSource

My problem is with this line (@"Amount", TypeCode.Int16, amount) .我的问题是这一行(@"Amount", TypeCode.Int16, amount) The specific error is C#: Unknown constructor Parameter(String, TypeCode, Int) of System.Web.UI.WebControls.Parameter .具体错误为C#: Unknown constructor Parameter(String, TypeCode, Int) of System.Web.UI.WebControls.Parameter Can someone point out what I did wrong?有人可以指出我做错了什么吗? Or, please tell me what steps I can take to debug this.或者,请告诉我可以采取哪些步骤来调试它。 I'm stuck.我被困住了。

    protected void InsertFees_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Command.Parameters["@UserID"].Value = Convert.ToInt16(RadGrid1.SelectedValues["UserID"].ToString());
    e.Command.Parameters["@Type"].Value = "D";
    e.Command.Parameters["@Date"].Value = DateTime.Now;
    e.Command.Parameters["@Amount"].Value = "";
    e.Command.Parameters["@Description"].Value = "";
}

protected void RadButton2_Click(object sender, EventArgs e)
{

    try
    {
        int amount = Convert.ToInt16(RadNumericTextBox1.Text);
        InsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int16, amount));
        InsertFees.InsertParameters.Add(new Parameter("@Description", TypeCode.String, RadTextBox2.Text));
        InsertFees.Insert();
        Label2.Text = "Insert Successful";
    }

    catch(Exception ex)
    {
        Panel1.Visible = true;
        Label3.Text = ex.ToString();
    }
}

int is an Int32, while Int16 is a Short int是 Int32,而 Int16 是Short

int amount

Maybe try this instead?也许试试这个?

short amount = Convert.ToInt16(RadNumericTextBox1.Text);
InsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int16, amount));

Or another way...或者其他方式...

int amount = Convert.ToInt32(RadNumericTextBox1.Text);
InsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int32, amount));

http://www.dotnetperls.com/int16-int32-int64 http://www.dotnetperls.com/int16-int32-int64

I agree with Bemused answer, but you need to pass the parameters to your SQLDataSource in this way.我同意Bemused回答,但您需要以这种方式将参数传递给您的 SQLDataSource。

InsertFees.InsertParameters["Amount"].DefaultValue = amount.ToString();

as you are adding parameters like.. InsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int16, amount));当您添加参数时,例如.. InsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int16, amount)); , It will add parameters again into Insert Parameters collection, which you have already defined in SQLDataSource InsertParameter collection , 它将再次将参数添加到您已经在 SQLDataSource InsertParameter 集合中定义的 Insert Parameters 集合中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 C# 中将 System.Web.UI.WebControls.Unit 转换为 int - Convert System.Web.UI.WebControls.Unit to int in c# ASP.NET C#在标签中显示数据-System.Web.UI.WebControls.Label - asp.net c# display data in label - System.Web.UI.WebControls.Label C#—无法将类型&#39;System.Web.UI.Control&#39;隐式转换为&#39;System.Web.UI.WebControls.CheckBox&#39; - C# — Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.CheckBox' C#本机类型的字节等效于System.Web.UI.WebControls.Unit - c# native type for bytes equivalent to System.Web.UI.WebControls.Unit C#ASP将自定义行为添加到每个System.Web.UI.WebControls.Button.OnClick事件 - C# ASP Add custom behavior to every System.Web.UI.WebControls.Button.OnClick event 无法从“字符串”转换为“ System.Web.UI.WebControls.TreeNode” - cannot convert from 'string' to 'System.Web.UI.WebControls.TreeNode' 无法从“ System.Web.UI.WebControls.Label”转换为“字符串”? - cannot convert from 'System.Web.UI.WebControls.Label' to 'string'? 无法从“字符串”转换为“System.Web.UI.WebControls.ListViewDataItem” - cannot convert from 'string' to 'System.Web.UI.WebControls.ListViewDataItem' 如何通过清单 <int> Web Api C#上SOAP UI的参数 - How to Pass List<int> parameter to SOAP UI on a Web Api C# C# 不存在从对象类型 System.Web.UI.WebControls.TextBox 到已知托管提供程序本机类型的映射 - C# No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM