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

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

ObjectDataSource.DeleteParameters プロパティ

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

DeleteMethod メソッドによって使用されるパラメータ格納するパラメータ コレクション取得します

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

Public ReadOnly Property
 DeleteParameters As ParameterCollection
Dim instance As ObjectDataSource
Dim value As ParameterCollection

value = instance.DeleteParameters
public ParameterCollection DeleteParameters { get;
 }
public:
property ParameterCollection^ DeleteParameters {
    ParameterCollection^ get ();
}
/** @property */
public ParameterCollection get_DeleteParameters ()
public function get DeleteParameters
 () : ParameterCollection

プロパティ
DeleteMethod メソッドによって使用されるパラメータ格納している ParameterCollection。

解説解説
使用例使用例

このセクションには、2 つコード例含まれています。1 つ目のコード例では、ビジネス オブジェクトおよび GridView コントロールで、ObjectDataSource オブジェクト使用してデータ削除する方法示します2 つ目のコード例では、1 つ目のコード例使用されている EmployeeLogic クラス示します

ビジネス オブジェクトおよび GridView コントロールで、ObjectDataSource コントロールDeleteParameters プロパティ使用してデータ削除する方法次のコード例示しますGridView コントロールは、SelectMethod プロパティ指定されメソッド使用して EmployeeLogic オブジェクトからデータ取得し最初に従業員表示します。AutoGenerateDeleteButton プロパティtrue設定されているため、GridView コントロール自動的に [削除] ボタン表示します

[削除] ボタンクリックすると、2 つパラメータで Deleting イベント呼び出されます。一方パラメータ EmpID は、DataGrid コントロールからのもので、DataKeyNames プロパティ基づいてます。もう一方パラメータは、宣言されDeleteParameters プロパティからのものです。EmployeeLogic クラスは、DeleteEmployee メソッドオーバーロードます。一方オーバーロードは、NorthwindEmployee パラメータ受け取り、もう一方anID という名前の Int32 パラメータ受け取りますDeleting イベントで、InputParameters プロパティのエントリは、original_EmpID の値を持つ anID という名前のパラメータ1 つだけ含めるように調整されます。イベント ハンドラ存在する場合は、一致する DeleteEmployee メソッド呼び出されます。

DataGrid コントロール表示しDeleting イベント処理する Web ページ次のコード例示します

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Import namespace="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<Script runat="server">
Private Sub NorthwindEmployeeDeleting(source
 As Object, e As ObjectDataSourceMethodEventArgs)

  Dim paramsFromPage As IDictionary = e.InputParameters

  paramsFromPage.Remove("anID")
  paramsFromPage.Add("anID", CInt(paramsFromPage("EmpID")))
  paramsFromPage.Remove("EmpID")

End Sub ' NorthwindEmployeeDeleting
</Script>

<html>
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post"
 runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratedeletebutton="true"
          DataKeyNames="EmpID">
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          deletemethod="DeleteEmployee"
          OnDeleting="NorthwindEmployeeDeleting"
          typename="Samples.AspNet.VB.EmployeeLogic">
          <deleteparameters>
            <asp:parameter name="anID" type="Int32"
 />
          </deleteparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
 Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<Script runat="server">
private void NorthwindEmployeeDeleting(object
 source, ObjectDataSourceMethodEventArgs e)
{
  IDictionary paramsFromPage = e.InputParameters;

  paramsFromPage.Remove("anID");
  paramsFromPage.Add("anID", (int)paramsFromPage["EmpID"]);
  paramsFromPage.Remove("EmpID");
    
}
</Script>

<html>
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratedeletebutton="true"
          DataKeyNames="EmpID">
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          deletemethod="DeleteEmployee"
          OnDeleting="NorthwindEmployeeDeleting"
          typename="Samples.AspNet.CS.EmployeeLogic">
          <deleteparameters>
            <asp:parameter name="anID" type="Int32" />
          </deleteparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL"
 Assembly="Samples.AspNet.JSL" %>
<%@ Import namespace="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<Script runat="server">
private void NorthwindEmployeeDeleting(Object
 source, 
    ObjectDataSourceMethodEventArgs e)  
    throws NorthwindDataException, System.Data.SqlClient.SqlException
{
    // The GridView passes the ID of the employee
    // to be deleted. However, it is named "EmpID", the name
    // of the property that the value is retrieved from
    // the NorthwindEmployee object. By default, this
    // name is passed as a parameter to the method
    // identified by the DeleteMethod property, which
    // in this case is named "anID". Because of the
    // naming discrepancy between "EmpID" and "anID"
,
    // the ObjectDataSource would throw an exception.
    // Therefore, rename the parameter from "EmpID" to
    // "anID".
    IDictionary paramsFromPage = e.get_InputParameters();

    NorthwindEmployee ne = new NorthwindEmployee(
        Convert.ToInt32(paramsFromPage.get_Item("EmpID")));
    // Remove the old parameter.
    paramsFromPage.Clear();
    paramsFromPage.Add("ne", ne);
}
</Script>

<html>
  <head>
    <title>ObjectDataSource - VJ# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratedeletebutton="true"
          datakeynames="EmpID">
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          deletemethod="DeleteEmployee"
          OnDeleting="NorthwindEmployeeDeleting"
          typename="Samples.AspNet.JSL.EmployeeLogic">
          <deleteparameters>
            <asp:parameter name="anID" type="Int32" />
          </deleteparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>

前のコード例使用されている EmployeeLogic クラス次のコード例示します

Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB
'
' EmployeeLogic is a stateless business object that encapsulates
' the operations you can perform on a NorthwindEmployee object.
Public Class EmployeeLogic

   ' Returns a collection of NorthwindEmployee objects.
   Public Shared Function
 GetAllEmployees() As ICollection
      Dim al As New ArrayList()

      ' Use the SqlDataSource class to wrap the
      ' ADO.NET code required to query the database.
      Dim cts As ConnectionStringSettings =
 ConfigurationManager.ConnectionStrings("NorthwindConnection")
      Dim sds As New SqlDataSource(cts.ConnectionString,
 "SELECT EmployeeID FROM Employees")
      Try
         Dim IDs As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)

         ' Iterate through the Enumeration and create a
         ' NorthwindEmployee object for each ID.
         Dim enumerator As IEnumerator = IDs.GetEnumerator()
         While enumerator.MoveNext()
            ' The IEnumerable contains DataRowView objects.
            Dim row As DataRowView = CType(enumerator.Current
,DataRowView)
            Dim id As String
 = row("EmployeeID").ToString()
                    Dim nwe As New
 NorthwindEmployee(CInt(id))
            ' Add the NorthwindEmployee object to the collection.
            al.Add(nwe)
         End While
      Finally
         ' If anything strange happens, clean up.
         sds.Dispose()
      End Try

      Return al
   End Function 'GetAllEmployees


   Public Shared Function
 GetEmployee(anID As Integer) As
 NorthwindEmployee
      Return New NorthwindEmployee(anID)
   End Function 'GetEmployee


   Public Shared Sub DeleteEmployee(ne
 As NorthwindEmployee)
      Dim retval As Boolean
 = ne.Delete()
      If Not retval Then
         Throw New NorthwindDataException("Employee
 delete failed.")
      End If ' Delete the object
 in memory.
      ne = Nothing
   End Sub 'DeleteEmployee


   Public Shared Sub DeleteEmployee(anID
 As Integer)
      Dim tempEmp As New
 NorthwindEmployee(anID)
      DeleteEmployee(tempEmp)
   End Sub 'DeleteEmployeeByID

   ' And so on...

End Class 'EmployeeLogic

Public Class NorthwindEmployee

   Public Sub New(anID As
 Integer)
      Me.ID = anID
      Dim cts As ConnectionStringSettings =
 ConfigurationManager.ConnectionStrings("NorthwindConnection")
      Dim conn As New SqlConnection(cts.ConnectionString)
      Dim sc As New SqlCommand("
 SELECT FirstName,LastName " & _
                               " FROM Employees "
 & _
                               " WHERE EmployeeID = @empId",
 conn)
      ' Add the employee ID parameter and set its value.
      sc.Parameters.Add(New SqlParameter("@empId",
 SqlDbType.Int)).Value = Int32.Parse(anID.ToString())
      Dim sdr As SqlDataReader = Nothing

      Try
         conn.Open()
         sdr = sc.ExecuteReader()

         ' This is not a while loop. It only loops once.
         If Not (sdr Is
 Nothing) AndAlso sdr.Read() Then
            ' The IEnumerable contains DataRowView objects.
            Me.firstName = sdr("FirstName").ToString()
            Me.lastName = sdr("LastName").ToString()
         Else
            Throw New NorthwindDataException("Data
 not loaded for employee id.")
         End If
      Finally
         Try
            If Not (sdr Is
 Nothing) Then
               sdr.Close()
            End If
            conn.Close()
         Catch se As SqlException
            ' Log an event in the Application Event Log.
            Throw
         End Try
      End Try
   End Sub 'New

   Private ID As Object
   Public ReadOnly Property
 EmpID() As Object
      Get
         Return ID
      End Get
   End Property

   Private aLastName As String
   Public Property LastName() As
 String
      Get
         Return aLastName
      End Get
      Set
         aLastName = value
      End Set
   End Property

   Private aFirstName As String
   Public Property FirstName() As
 String
      Get
         Return aFirstName
      End Get
      Set
         aFirstName = value
      End Set
   End Property

   Public Function Delete() As
 Boolean
      If ID.Equals(DBNull.Value) Then
         ' The Employee object is not persisted.
         Return True
      Else
         ' The Employee object is persisted.
         ' Use the SqlDataSource control as a convenient wrapper for
         ' the ADO.NET code needed to delete a record from the database.
         Dim cts As ConnectionStringSettings =
 ConfigurationManager.ConnectionStrings("NorthwindConnection")
         Dim sds As New
 SqlDataSource()
         Try
            sds.ConnectionString = cts.ConnectionString
            sds.DeleteCommand = "DELETE FROM Employees WHERE EmployeeID=@empID;"
                    Dim param As New
 Parameter("empID", TypeCode.Int32, CStr(Me.ID))
            sds.DeleteParameters.Add(param)

            ' To make this sample fully functional, uncomment these
 lines
'          int retval = sds.Delete();
'          if (retval == 1) { return true; }
'          return false;

            Return True
         Finally
            sds.Dispose()
         End Try
      End If
   End Function 'Delete

End Class 'NorthwindEmployee

Friend Class NorthwindDataException
   Inherits Exception

   Public Sub New(msg As
 String)
      MyBase.New(msg)
   End Sub 'New
End Class 'NorthwindDataException

End Namespace
namespace Samples.AspNet.CS {

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
  //
  // EmployeeLogic is a stateless business object that encapsulates
  // the operations you can perform on a NorthwindEmployee object.
  //
  public class EmployeeLogic {

    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees
 () {
      ArrayList al = new ArrayList();

      // Use the SqlDataSource class to wrap the
      // ADO.NET code required to query the database.
      ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

      SqlDataSource sds
        = new SqlDataSource(cts.ConnectionString,
                            "SELECT EmployeeID FROM Employees");
      try {
        IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

        // Iterate through the Enumeration and create a
        // NorthwindEmployee object for each ID.
        IEnumerator enumerator = IDs.GetEnumerator();
        while (enumerator.MoveNext()) {
          // The IEnumerable contains DataRowView objects.
          DataRowView row = enumerator.Current as DataRowView;
          int id = (int) row["EmployeeID"];
          NorthwindEmployee nwe = new NorthwindEmployee(id);
          // Add the NorthwindEmployee object to the collection.
          al.Add(nwe);
        }
      }
      finally {
        // If anything strange happens, clean up.
        sds.Dispose();
      }

      return al;
    }

    public static NorthwindEmployee GetEmployee(int
 anID) {
      return new NorthwindEmployee(anID);
    }

    public static void DeleteEmployee(NorthwindEmployee
 ne) {
      bool retval = ne.Delete();
      if (! retval) { throw new NorthwindDataException("Employee
 delete failed."); }
      // Delete the object in memory.
      ne = null;
    }

    public static void DeleteEmployee(int
 anID) {
        NorthwindEmployee tempEmp = new NorthwindEmployee(anID);
        DeleteEmployee(tempEmp);
    }
  }
  public class NorthwindEmployee {

    public NorthwindEmployee (int anID) {
      this.ID = anID;

      ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];
      SqlConnection conn = new SqlConnection (cts.ConnectionString);
      SqlCommand sc =
        new SqlCommand(" SELECT FirstName,LastName "
 +
                       " FROM Employees " +
                       " WHERE EmployeeID = @empId",
                       conn);
      // Add the employee ID parameter and set its value.
      sc.Parameters.Add(new SqlParameter("@empId",SqlDbType.Int)).Value
 = Int32.Parse(anID.ToString());
      SqlDataReader sdr = null;

      try {
        conn.Open();
        sdr = sc.ExecuteReader();

        // This is not a while loop. It only loops once.
        if (sdr != null && sdr.Read())
 {
          // The IEnumerable contains DataRowView objects.
          this.firstName        = sdr["FirstName"].ToString();
          this.lastName         = sdr["LastName"].ToString();
        }
        else {
          throw new NorthwindDataException("Data not loaded
 for employee id.");
        }
      }
      finally {
        try {
          if (sdr != null) sdr.Close();
          conn.Close();
        }
        catch (SqlException) {
          // Log an event in the Application Event Log.
          throw;
        }
      }
    }

    private object ID;
    public object EmpID {
      get { return ID; }
    }

    private string lastName;
    public string LastName {
      get { return lastName; }
      set { lastName = value; }
    }

    private string firstName;
    public string FirstName {
      get { return firstName; }
      set { firstName = value;  }
    }
    public bool Delete () {
      if (ID.Equals(DBNull.Value)) {
        // The Employee object is not persisted.
        return true;
      }
      else {
        // The Employee object is persisted.
        // Use the SqlDataSource control as a convenient wrapper for
        // the ADO.NET code needed to delete a record from the database.
        ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];
        SqlDataSource sds = new SqlDataSource();
        try {
          sds.ConnectionString = cts.ConnectionString;
          sds.DeleteCommand = "DELETE FROM Employees WHERE EmployeeID=@empID;";
          sds.DeleteParameters.Add(new Parameter("empID"
,TypeCode.Int32,this.ID.ToString()));

          /* To make this sample fully functional, uncomment these
 lines
          int retval = sds.Delete();
          if (retval == 1) { return true;
 }
          return false; */

          return true;
        }
        finally {
          sds.Dispose();
        }
      }
    }
  }
  internal class NorthwindDataException: Exception {
    public NorthwindDataException(string msg)
 : base (msg) { }
  }
}
package Samples.AspNet.JSL;

import System.*;
import System.Collections.*;
import System.Configuration.*;
import System.Data.*;
import System.Data.SqlClient.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
//
// EmployeeLogic is a stateless business object that encapsulates
// the operations you can perform on a NorthwindEmployee object.
//
public class EmployeeLogic
{
    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees()
 
        throws NorthwindDataException, SqlException
    {
        ArrayList al = new ArrayList();

        // Use the SqlDataSource class to wrap the
        // ADO.NET code required to query the database.
        ConnectionStringSettings cts = ConfigurationManager.get_ConnectionStrings().
            get_Item("NorthwindConnection");

        SqlDataSource sds = new SqlDataSource(cts.get_ConnectionString(),
 
            "SELECT EmployeeID FROM Employees");
        try {
            IEnumerable ids = sds.Select(DataSourceSelectArguments.get_Empty());

            // Iterate through the Enumeration and create a
            // NorthwindEmployee object for each ID.
            IEnumerator enumerator = ids.GetEnumerator();
            while (enumerator.MoveNext()) {
                // The IEnumerable contains DataRowView objects.
                DataRowView row = (DataRowView)enumerator.get_Current();
                int id = Convert.ToInt32(row.get_Item("EmployeeID"));
                NorthwindEmployee nwe = new NorthwindEmployee(id);
                // Add the NorthwindEmployee object to the collection.
                al.Add(nwe);
            }
        }
        finally {
            // If anything strange happens, clean up.
            sds.Dispose();
        }

        return al;
    } //GetAllEmployees

    public static NorthwindEmployee GetEmployee(int
 anId) 
        throws NorthwindDataException, SqlException
    {
        return new NorthwindEmployee(anId);
    } //GetEmployee

    public static void DeleteEmployee(NorthwindEmployee
 ne) 
        throws NorthwindDataException
    {
        boolean retval = ne.Delete();
        if (!retval) {
            throw new NorthwindDataException("Employee delete
 failed.");
        }
        // Delete the object in memory.
        ne = null;
    } //DeleteEmployee

    public static void DeleteEmployeeByID(int
 anId) 
        throws NorthwindDataException, SqlException
    {
        NorthwindEmployee tempEmp = new NorthwindEmployee(anId);
        DeleteEmployee(tempEmp);
    } //DeleteEmployeeByID
} //EmployeeLogic

public class NorthwindEmployee
{
    public NorthwindEmployee(int anId) 
        throws NorthwindDataException, SqlException
    {
        this.id = (Int32)anId;

        ConnectionStringSettings cts = ConfigurationManager.get_ConnectionStrings().
            get_Item("NorthwindConnection");
        SqlConnection conn = new SqlConnection(cts.get_ConnectionString());
        SqlCommand sc = new SqlCommand(" SELECT FirstName,LastName
 " 
            + " FROM Employees WHERE EmployeeID = @empId", conn);

        // Add the employee ID parameter and set its value.
        sc.get_Parameters().Add(new SqlParameter("@empId",
 SqlDbType.Int)).
            set_Value((Int32)Int32.Parse(Convert.ToString(anId)));
        SqlDataReader sdr = null;

        try {
            conn.Open();
            sdr = sc.ExecuteReader();

            // This is not a while loop. It only loops once.
            if (sdr != null && sdr.Read())
 {
                // The IEnumerable contains DataRowView objects.
                this.firstName = sdr.get_Item("FirstName").ToString();
                this.lastName = sdr.get_Item("LastName").ToString();
            }
            else {
                throw new NorthwindDataException("Data not
 loaded for employee "
                    + "id.");
            }
        }
        finally {
            try {
                if (sdr != null) {
                    sdr.Close();
                }
                conn.Close();
            }
            catch (SqlException exp) {
                // Log an event in the Application Event Log.
                throw exp;
            }
        }
    } //NorthwindEmployee

    private Object id;

    /** @property 
     */
    public Object get_EmpID()
    {
        return id;
    } //get_EmpID

    private String lastName;

    /** @property 
     */
    public String get_LastName()
    {
        return lastName;
    } //get_LastName

    /** @property 
     */
    public void set_LastName(String value)
    {
        lastName = value;
    } //set_LastName

    private String firstName;

    /** @property 
     */
    public String get_FirstName()
    {
        return firstName;
    } //get_FirstName

    /** @property 
     */
    public void set_FirstName(String value)
    {
        firstName = value;
    } //set_FirstName

    public boolean Delete()
    {
        if (id.Equals(DBNull.Value)) {
            // The Employee object is not persisted.
            return true;
        }
        else {
            // The Employee object is persisted.
            // Use the SqlDataSource control as a convenient wrapper
 for
            // the ADO.NET code needed to delete a record from the database.
            ConnectionStringSettings cts = ConfigurationManager.
                get_ConnectionStrings().get_Item("NorthwindConnection");
            SqlDataSource sds = new SqlDataSource();
            try {
                sds.set_ConnectionString(cts.get_ConnectionString());
                sds.set_DeleteCommand("DELETE FROM Employees WHERE "
                    + "EmployeeID=@empID;");
                sds.get_DeleteParameters().Add(new Parameter("empID",
 
                    TypeCode.Int32, this.id.ToString()));

                /* To make this sample fully functional, uncomment these
 lines
                int retval = sds.Delete();
                if (retval == 1) { return true;
 }
                return false; 
                */
                return true;
            }
            finally {
                sds.Dispose();
            }
        }
    } //Delete
} //NorthwindEmployee

public class NorthwindDataException extends
 System.Exception
{
    public NorthwindDataException(String msg)
    {
         super(msg);
    } //NorthwindDataException
} //NorthwindDataException
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSource クラス
ObjectDataSource メンバ
System.Web.UI.WebControls 名前空間
ObjectDataSource.DeleteMethod プロパティ
Delete


このページでは「.NET Framework クラス ライブラリ リファレンス」からObjectDataSource.DeleteParameters プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からObjectDataSource.DeleteParameters プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からObjectDataSource.DeleteParameters プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「ObjectDataSource.DeleteParameters プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS