2011-07-18 9 views
0

私のコードの背後には、以下のコードが挿入コマンドを実行しています。ユーザーが特定のボタンをクリックすると、2つのパラメーター値が設定されます。私はSqlDataSourceを再利用したいので、この方法で壊しました。C#:Unknown constructor 'System.Web.UI.WebControls.Parameter'の 'Parameter(String、TypeCode、Int)'

私の問題はこの行にあります(@"Amount", TypeCode.Int16, amount)。具体的なエラーはC#: Unknown constructor Parameter(String, TypeCode, Int) of System.Web.UI.WebControls.Parameterです。誰かが私が間違ったことを指摘できますか?または、これをデバッグするために私が取ることができるステップを教えてください。私は立ち往生している。

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(); 
    } 
} 
+0

で定義されている挿入Parametersコレクションへ再びパラメータを追加しますこの機能は.NET 2.0以降のサービスパックに含まれていたため、 –

答えて

0

私はBemused答えに同意しますが、この方法であなたをSqlDataSourceにパラメータを渡す必要があります。

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

あなたはInsertFees.InsertParameters.Add(new Parameter("@Amount", TypeCode.Int16, amount)); ...のようなパラメータを追加しているとして、それはあなたがすでにあなたは上の `の.NET framework`にパッチを適用する必要があるのSqlDataSource InsertParameterコレクション

+0

ありがとうございます。上記のコードではどのようにdbtypeを指定しますか?それは文字列を期待していると私はそれをintに与える必要があります。 – hughesdan

+0

amount.ToString()を使用して値を渡すことができます。DefaultValueプロパティには文字列値が必要ですが、SQLDataSourceこれは自動的にSQLDataSourceのInsert Parameterコレクションに記述されています。 –

+0

またはあなたが試みることができる:InsertFees.InsertParameters ["Amount"]。DbType = TypeCode.Int16 –

2

int型はInt16型がショート

int amount 

はたぶん、代わりにこれを試している間に、int32ですか?

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

それとも別の方法...

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

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

+0

ありがとう...私はint 32 intを認識しませんでした。今日何かを学んだ。残念ながら、提案された修正は同じエラーを返します。 – hughesdan

関連する問題