SqlDataSourceView.OnDeleting メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim e As SqlDataSourceCommandEventArgs Me.OnDeleting(e)

イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの利用」を参照してください。
OnDeleting メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnDeleting メソッドをオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnDeleting メソッドを呼び出してください。
Delete 操作が発生する前に発生する Deleting イベントを処理する方法を次のコード例に示します。この例では Northwind データベースからデータを削除するため、削除の実行前にデータベースをディスクにバックアップしようと試みる OnDeleting ハンドラが追加されています。
<%@Page Language="VB" %> <%@Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <SCRIPT runat="server"> Sub On_Record_Deleting(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs) ' Cancel the delete operation if the checkbox is not checked. If Not CheckBox1.Checked e.Cancel = True Label1.Text = "The command was cancelled because the CheckBox was not checked." End If End Sub 'On_Record_Deleting Sub On_Record_Deleted(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs) Label1.Text = e.AffectedRows & " row(s) were deleted" End Sub </SCRIPT> <HTML> <BODY> <FORM runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>" SelectCommand="SELECT * FROM Orders" DeleteCommand="DELETE FROM [Order Details] WHERE OrderID=@OrderID;DELETE FROM Orders WHERE OrderID=@OrderID;" OnDeleting="On_Record_Deleting" OnDeleted="On_Record_Deleted"> </asp:SqlDataSource> <br /> <asp:CheckBox id="CheckBox1" runat="server" autopostback="true" text="Check To Delete Data" /> <br /> <br /> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID" AutoGenerateDeleteButton="True" AllowPaging="True" PageSize="20" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField HeaderText="Order ID" DataField="OrderID" /> <asp:BoundField HeaderText="Customer" DataField="CustomerID" /> <asp:BoundField HeaderText="Order Placed" DataField="OrderDate" /> <asp:BoundField HeaderText="Order Shipped" DataField="ShippedDate" /> </Columns> </asp:GridView> <asp:Label id="Label1" runat="server"> </asp:Label> </FORM> </BODY> </HTML>
<%@Page Language="C#" %> <%@Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <SCRIPT runat="server"> private void OnRecordDeleting(Object source, SqlDataSourceCommandEventArgs e) { // Cancel the delete operation if the checkbox is not checked. if (! CheckBox1.Checked) { e.Cancel = true; Label1.Text = "The command was cancelled because the CheckBox was not checked."; } } private void OnRecordDeleted(object source, SqlDataSourceStatusEventArgs e) { Label1.Text = e.AffectedRows + " row(s) were deleted"; } </SCRIPT> <HTML> <BODY> <FORM runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>" SelectCommand="SELECT * FROM Orders" DeleteCommand="DELETE FROM [Order Details] WHERE OrderID=@OrderID;DELETE FROM Orders WHERE OrderID=@OrderID;" OnDeleting="OnRecordDeleting" OnDeleted="OnRecordDeleted"> </asp:SqlDataSource> <br /> <asp:CheckBox id="CheckBox1" runat="server" autopostback="true" text="Check To Delete Data" /> <br /> <br /> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID" AutoGenerateDeleteButton="True" AllowPaging="True" PageSize="20" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField HeaderText="Order ID" DataField="OrderID" /> <asp:BoundField HeaderText="Customer" DataField="CustomerID" /> <asp:BoundField HeaderText="Order Placed" DataField="OrderDate" /> <asp:BoundField HeaderText="Order Shipped" DataField="ShippedDate" /> </Columns> </asp:GridView> <asp:Label id="Label1" runat="server"> </asp:Label> </FORM> </BODY> </HTML>
<%@Page Language="VJ#" %> <%@Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <SCRIPT runat="server"> private void OnRecordDeleting(Object source, SqlDataSourceCommandEventArgs e) { // Because this example actually deletes data from the Northwind // database, provide a way for users to recover any deleted records. SqlConnection cxn = new SqlConnection( "Data Source=localhost;Integrated Security=SSPI;" + "Initial Catalog=Northwind;Connect Timeout=15"); try { cxn.Open(); SqlCommand backup = new SqlCommand(); backup.set_Connection (cxn); backup.set_CommandText( " USE master " + " EXEC sp_addumpdevice 'disk','Northwind_1'," + "'c:\\temp\\Northwind_1.dat'" + " BACKUP DATABASE Northwind TO Northwind_1"); backup.ExecuteNonQuery(); } catch (SqlException se) { // Handle an exception thrown if the device already exists. Label1.set_Text("An error occurred while backing up your " + "database. Please check the SQL logs."); } finally { // Always release the connection. cxn.Dispose(); } Label1.set_Text("A record has been deleted. To recover your data, " + "restore the database from the " + "database backup named Northwind_1.dat located on the database " + "server in c:\\temp."); } //OnRecordDeleting </SCRIPT> <HTML> <BODY> <FORM runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;" SelectCommand="SELECT * FROM Orders" DeleteCommand="DELETE FROM [Order Details] WHERE OrderID=@OrderID;DELETE FROM Orders WHERE OrderID=@OrderID;" OnDeleting="OnRecordDeleting"> </asp:SqlDataSource> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID" AutoGenerateDeleteButton="True" AllowPaging="True" PageSize="20" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField HeaderText="Order ID" DataField="OrderID" /> <asp:BoundField HeaderText="Customer" DataField="CustomerID" /> <asp:BoundField HeaderText="Order Placed" DataField="OrderDate" /> <asp:BoundField HeaderText="Order Shipped" DataField="ShippedDate" /> </Columns> </asp:GridView> <asp:Label id="Label1" runat="server"> </asp:Label> </FORM> </BODY> </HTML>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSqlDataSourceView.OnDeleting メソッドを検索する場合は、下記のリンクをクリックしてください。

- SqlDataSourceView.OnDeleting メソッドのページへのリンク