开发者

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开发者_StackOverflow中文版 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.

My problem is with this line (@"Amount", TypeCode.Int16, amount). The specific error is 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 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


I agree with Bemused answer, but you need to pass the parameters to your SQLDataSource in this way.

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

as you are adding parameters like..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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜