[英]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.