2

このテーマについて質問しました。すべての行には、Gridviewに削除ボタンがあります

簡単なテーブルがありますAVUKAT

列- > HESAP、、MUSTERIAVUKAT

そして、Gridviewにデータを表示します。

アクティベートしAutoGenerateDeleteButtonます。

ここに画像の説明を入力してください

しかし、行の[削除]ボタンをクリックすると、次のようなエラーが発生します。

Server Error in '/' Application.
Deleting is not supported by data source 'GridviewDataSource' unless DeleteCommand is specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Deleting is not supported by data source 'GridviewDataSource' unless DeleteCommand is specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

削除ボタンをクリックすると、どの機能が有効になりますか?

この関数のコードはどうあるべきですか?

4

3 に答える 3

2

このMSDNの記事をご覧ください:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.deletecommand.aspx#Y725

データベースからデータを削除するためのSQLDataSourceの設定について説明します。

アップデート

SQLDataSourceに「パラメータの削除」(MSDNリンク)がありません。

SQLDataSourceを更新して、次のようにDeleteParametersを含めます(ControlParametersのConnectionStringやControlIDなどを更新する必要があります)。

<asp:SqlDataSource
   id="SqlDataSource1"
   runat="server"
   ConnectionString="myConnectionString"
   SelectCommand="SELECT * FROM [AVUKAT] ORDER BY [MUSTERI]" 
   DeleteCommand="DELETE FROM [AVUKAT] WHERE MUSTERI = @MUSTERI AND AVUKAT = @AVUKAT AND HESAP = @HESAP">
   <DeleteParameters>
      <asp:ControlParameter Name="MUSTERI" ControlId="DropDownListID" PropertyName="SelectedValue" />
      <asp:ControlParameter Name="AVUKAT" ControlId="DropDownListID" PropertyName="SelectedValue" />
      <asp:ControlParameter Name="HESAP" ControlId="DropDownListID" PropertyName="SelectedValue" />
   </DeleteParameters>
</asp:SqlDataSource>
于 2011-02-11T13:26:55.790 に答える
1

これとは別に、このDeleteコマンドを実行するテーブルで主キーを使用することを忘れないでください。主キーがない場合、複数の行が同じ値になると、生成されるクエリがあいまいになる可能性があるため、deleteコマンドは例外をスローします(実際、テーブルに主キー。)

于 2011-06-22T17:10:02.893 に答える
0

このチュートリアルで説明されているように、RowDeletingイベントを実装する必要があります。

于 2011-02-11T13:26:11.550 に答える