SqlDataSourceView.DeleteCommand プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataSourceView.DeleteCommand プロパティの意味・解説 

SqlDataSourceView.DeleteCommand プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

基になるデータベースからデータ削除するために SqlDataSourceView が使用する SQL 文字列取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As SqlDataSourceView
Dim value As String

value = instance.DeleteCommand

instance.DeleteCommand = value
public string DeleteCommand { get;
 set; }
public:
property String^ DeleteCommand {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_DeleteCommand ()

/** @property */
public void set_DeleteCommand (String value)
public function get DeleteCommand
 () : String

public function set DeleteCommand
 (value : String)

プロパティ
データ削除するために SqlDataSourceView使用する SQL 文字列

解説解説

異なデータベース製品では異な種類SQL使用されるため、SQL 文字列構文は、現在使用されている ADO.NET プロバイダによって異なります。このプロバイダは、ProviderName プロパティによって示されます。

SQL 文字列パラメータ化されたクエリまたはコマンドである場合パラメータのプレースホルダは、使用されている ADO.NET プロバイダ依存します。たとえば、プロバイダが SqlDataSource クラス既定プロバイダである System.Data.SqlClient の場合パラメータのプレースホルダは '@parameterName' です。ただし、プロバイダが System.Data.Odbc または System.Data.OleDb に設定されている場合パラメータのプレースホルダは '?' となりますパラメータ化された SQL クエリコマンド詳細については、「SqlDataSource コントロールにおけるパラメータ使用」を参照してください

基になるデータベースストアド プロシージャサポートしている場合DeleteCommand には、SQL 文字列またはストアド プロシージャの名前を指定できます

DeleteCommand プロパティの値はビューステート格納されます。

使用例使用例

DeleteCommand テキスト設定してNorthwind データベースOrders テーブルから発注内容削除する方法次のコード例示しますデータOrders テーブルから取得され、GridView コントロール表示されます。GridView は、AutoGenerateDeleteButton プロパティtrue設定されている場合自動的に [削除] ボタン描画ます。また、[削除] ボタンクリックすると、自動的に DeleteParameters コレクションの値を設定しDelete メソッド呼び出します。最後に、この例ではデータ削除するため、削除操作実行前にデータベースディスクバックアップしようと試みイベント ハンドラ追加されています。

<%@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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSourceView クラス
SqlDataSourceView メンバ
System.Web.UI.WebControls 名前空間
ExecuteDelete
Delete
DeleteParameters



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SqlDataSourceView.DeleteCommand プロパティ」の関連用語

SqlDataSourceView.DeleteCommand プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlDataSourceView.DeleteCommand プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS