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

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

ObjectDataSource.InsertMethod プロパティ

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

ObjectDataSource コントロールデータ挿入するために呼び出すメソッドまたは関数の名前を取得または設定します

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

Dim instance As ObjectDataSource
Dim value As String

value = instance.InsertMethod

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

/** @property */
public void set_InsertMethod (String value)
public function get InsertMethod
 () : String

public function set InsertMethod
 (value : String)

プロパティ
ObjectDataSourceデータ挿入するために使用するメソッドまたは関数の名前を表す文字列。既定値空の文字列 ("") です。

解説解説

ビジネス オブジェクトは、バッチではなく一度に 1 レコードずつデータ挿入することを前提としています。

InsertMethod プロパティは、ObjectDataSource オブジェクト関連付けられた ObjectDataSourceView オブジェクトの InsertMethod プロパティに処理を代行させます

オブジェクト有効期間
パラメータマージ

パラメータは、次の 3 つのソースから InsertParameters コレクション追加されます。

まず、データ バインド コントロールか生成されパラメータInsertParameters コレクション追加されます。たとえば、ObjectDataSource コントロールName 列と Number 列を持つ GridView コントロールバインドされている場合Name および Number対応するパラメータコレクション追加されます。これらのパラメータデータ型string です。次にInsertParameters 要素リストされたパラメータ追加されます。InsertParameters 要素パラメータInsertParameters コレクション内の既存パラメータと同じ名前で存在する場合InsertParameters 要素指定されパラメータ一致するように既存パラメータ変更されます。通常、これはパラメータデータの型を変更するために使用されます。最後に、Inserting イベントプログラムによってパラメータ追加および削除できます。このイベントは、Insert メソッド実行される前に発生しますメソッドは、パラメータマージされた後に解決されます。メソッド解決については、次のセクション説明します

メソッド解決

Insert メソッド呼び出されると、データ バインド コントロールデータ フィールドInsertParameters 要素宣言によって作成されパラメータ、および Inserting イベント ハンドラ追加されパラメータがすべてマージされます (詳細については、前のセクション参照してください)。次にObjectDataSource オブジェクトは、呼び出すメソッド検索試みます。まず、InsertMethod プロパティ指定された名前を持つ 1 つ上のメソッド検索されます。一致するメソッドが見つからない場合、InvalidOperationException 例外スローさます。一致するメソッド見つかった場合は、一致するパラメータ名が検索されます。たとえば、TypeName プロパティ指定された型に InsertARecord という名前のメソッド2 つあるとします一方InsertARecord には、ID というパラメータ1 つあり、もう一方InsertARecord には、NameNumber という 2 つパラメータありますInsertParameters コレクションID という名前のパラメータ1 つしかない場合ID パラメータだけを持つ InsertARecord メソッド呼び出されます。メソッド解決時にパラメータの型はチェックされません。パラメータ順序は重要ではありません。

DataObjectTypeName プロパティ設定されている場合には、メソッド別の方法解決されます。ObjectDataSource は、DataObjectTypeName プロパティ指定された型のパラメータ1 つ受け取InsertMethod プロパティ指定された名前のメソッド検索します。この場合パラメータの名前は重要ではありません。

使用例使用例

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

ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource コントロール使用してデータ挿入する方法次のコード例示します。まず、DetailsView は、新しNorthwindEmployee レコード自動生成された [挿入] ボタン表示しますDetailsView コントロールフィールドデータ入力した後、[挿入] ボタンクリックします。InsertMethod プロパティは、挿入操作実行するメソッド識別します。

この例では、UpdateEmployeeInfo メソッド挿入実行使用されます。ただし、データ挿入するためには、NorthwindEmployee パラメータが必要です。したがってDetailsView コントロール自動的にす文字列のコレクションだけでは不十分です。NorthwindEmployeeInserting デリゲートInserting イベント処理する ObjectDataSourceMethodEventHandler オブジェクトで、これを使用することにより、Insert 操作続行される前に入力パラメータ操作できますUpdateEmployeeInfo メソッドでは、パラメータとして NorthwindEmployee オブジェクトを必要とするため、文字列コレクション使用してオブジェクト作成されメソッド必要なパラメータ名 (ne) を使用して、InputParameters コレクション追加されます。ObjectDataSource コントロール使用するために特別にデザインされているわけではない型とメソッドを持つデータ ソースとして、既存中間層オブジェクト使用する場合は、これらと同様の手順実行します

Insert 操作実行すると、InsertMethod プロパティ識別されメソッド呼び出されます。オブジェクトInsert メソッドパラメータを含むメソッド シグネチャ持っている場合Insert メソッド正常に完了するには、InsertParameters コレクションメソッド シグネチャ パラメータ一致する名前のパラメータ含まれている必要があります

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

  ' The GridView control passes an array of strings in the parameters
  ' collection because that is the type it knows how to work with.
  ' However, the business object expects a custom type. Build it
  ' and add it to the parameters collection.
  Dim paramsFromPage As IDictionary = e.InputParameters

  Dim ne As New NorthwindEmployee()
  ne.FirstName  = paramsFromPage("FirstName").ToString()
  ne.LastName   = paramsFromPage("LastName").ToString()
  ne.Title      = paramsFromPage("Title").ToString()
  ne.Courtesy   = paramsFromPage("Courtesy").ToString()
  ne.Supervisor = Int32.Parse(paramsFromPage("Supervisor").ToString())
  
  paramsFromPage.Clear()
  paramsFromPage.Add("ne", ne)
End Sub ' NorthwindEmployeeInserting

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

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="UpdateEmployeeInfo"
          oninserting="NorthwindEmployeeInserting"
          typename="Samples.AspNet.VB.EmployeeLogic"
 >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1"
 />
          </selectparameters>
        </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 NorthwindEmployeeInserting(object
 source, ObjectDataSourceMethodEventArgs e)
{
  // The business object expects a custom type. Build it
  // and add it to the parameters collection.
  
  IDictionary paramsFromPage = e.InputParameters;

  NorthwindEmployee ne = new NorthwindEmployee();

  ne.FirstName  = paramsFromPage["FirstName"].ToString();
  ne.LastName   = paramsFromPage["LastName"].ToString();
  ne.Title      = paramsFromPage["Title"].ToString();
  ne.Courtesy   = paramsFromPage["Courtesy"].ToString();
  ne.Supervisor = Int32.Parse(paramsFromPage["Supervisor"].ToString());

  paramsFromPage.Clear();
  paramsFromPage.Add("ne", ne);
}

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

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="UpdateEmployeeInfo"
          oninserting="NorthwindEmployeeInserting"
          typename="Samples.AspNet.CS.EmployeeLogic"
          >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
        </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 NorthwindEmployeeInserting(Object
 source,
    ObjectDataSourceMethodEventArgs e)
{
    // The GridView control passes an array of strings in the parameters
    // collection because that is the type it knows how to work with.
    // However, the business object expects a custom type. Build it
    // and add it to the parameters collection.
    IDictionary paramsFromPage = e.get_InputParameters();

    NorthwindEmployee ne =  new NorthwindEmployee();
    ne.set_FirstName(paramsFromPage.get_Item("FirstName").ToString());
    ne.set_LastName (paramsFromPage.get_Item("LastName").ToString());
    ne.set_Title(paramsFromPage.get_Item("Title").ToString());
    ne.set_Courtesy(paramsFromPage.get_Item("Courtesy").ToString());
    ne.set_Supervisor(Int32.Parse(paramsFromPage.
        get_Item("Supervisor").ToString()));

    paramsFromPage.Clear();
    paramsFromPage.Add("ne", ne);
}

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

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="UpdateEmployeeInfo"
          oninserting="NorthwindEmployeeInserting"
          typename="Samples.AspNet.JSL.EmployeeLogic" >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

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

前のコード例使用した中間層ビジネス オブジェクトの例を提供するコード例次に示します。このコード例は、次の 2 つ基本クラス構成されます。

便宜上追加NorthwindDataException クラス提供されています。実際に動作させるためには、これらのクラスコンパイルして使用する必要がありますUpdateEmployeeInfo メソッドは、完全には実装されていません。そのため、この例を実行しても、Northwind Traders データベースデータ挿入されません。

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()

      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(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 Object) As
 NorthwindEmployee
      If anID.Equals("-1") OrElse
 anID.Equals(DBNull.Value) Then
         Return New NorthwindEmployee()
      Else
         Return New NorthwindEmployee(anID)
      End If
   End Function 'GetEmployee


   Public Shared Sub UpdateEmployeeInfo(ne
 As NorthwindEmployee)
      Dim retval As Boolean
 = ne.Save()
      If Not retval Then
         Throw New NorthwindDataException("UpdateEmployee
 failed.")
      End If
   End Sub 'UpdateEmployeeInfo

   Public Shared Sub DeleteEmployee(ne
 As NorthwindEmployee)
      Dim retval As Boolean
 = ne.Delete()
      If Not retval Then
         Throw New NorthwindDataException("DeleteEmployee
 failed.")
      End If
   End Sub 'DeleteEmployee

   ' And so on...

End Class 'EmployeeLogic


Public Class NorthwindEmployee


   Public Sub New()
      ID = DBNull.Value
      lastName = ""
      firstName = ""
      title = ""
      titleOfCourtesy = ""
      reportsTo = - 1
   End Sub 'New


   Public Sub New(anID As
 Object)
      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,Title,TitleOfCourtesy,ReportsTo " & _
                               " 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()

         ' Only loop once.
         If Not (sdr Is
 Nothing) AndAlso sdr.Read() Then
            ' The IEnumerable contains DataRowView objects.
            Me.aFirstName = sdr("FirstName").ToString()
            Me.aLastName = sdr("LastName").ToString()
            Me.aTitle = sdr("Title").ToString()
            Me.titleOfCourtesy = sdr("TitleOfCourtesy").ToString()
            If Not sdr.IsDBNull(4) Then
               Me.reportsTo = sdr.GetInt32(4)
            End If
         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 String
      Get
         Return ID.ToString()
      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 ReadOnly Property
 FullName() As String
      Get
         Return FirstName & " "
 & LastName
      End Get
   End Property

   Private aTitle As String
   Public Property Title() As
 String
      Get
         Return aTitle
      End Get
      Set
         aTitle = value
      End Set
   End Property

   Private titleOfCourtesy As String
   Public Property Courtesy() As
 String
      Get
         Return titleOfCourtesy
      End Get
      Set
         titleOfCourtesy = value
      End Set
   End Property

   Private reportsTo As Integer
   Public Property Supervisor() As
 Integer
      Get
         Return reportsTo
      End Get
      Set
         reportsTo = value
      End Set
   End Property

   Public Function Save() As
 Boolean

      ' Implement persistence logic.
      Return True

   End Function 'Save


   Public Function Delete() As
 Boolean

     ' Implement delete logic.
     Return True

   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();

      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;
          string id = row["EmployeeID"].ToString();
          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(object
 anID) {
      if (anID.Equals("-1") ||
          anID.Equals(DBNull.Value) ) {
        return new NorthwindEmployee();
      }
      else {
        return new NorthwindEmployee(anID);
      }
    }

    public static void UpdateEmployeeInfo(NorthwindEmployee
 ne) {
      bool retval = ne.Save();
      if (! retval) { throw new NorthwindDataException("UpdateEmployee
 failed."); }
    }

    public static void DeleteEmployee(NorthwindEmployee
 ne) {
      bool retval = ne.Delete();
      if (! retval) { throw new NorthwindDataException("DeleteEmployee
 failed."); }
    }

    // And so on...
  }

  public class NorthwindEmployee {

    public NorthwindEmployee () {
      ID = DBNull.Value;
      lastName = "";
      firstName = "";
      title="";
      titleOfCourtesy = "";
      reportsTo = -1;
    }

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

      SqlConnection conn
        = new SqlConnection (ConfigurationManager.ConnectionStrings["NorthwindConnection"].ConnectionString);
      SqlCommand sc =
        new SqlCommand(" SELECT FirstName,LastName,Title,TitleOfCourtesy,ReportsTo
 " +
                       " 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();

        // Only loop once.
        if (sdr != null && sdr.Read())
 {
          // The IEnumerable contains DataRowView objects.
          this.firstName        = sdr["FirstName"].ToString();
          this.lastName         = sdr["LastName"].ToString();
          this.title            = sdr["Title"].ToString();
          this.titleOfCourtesy  = sdr["TitleOfCourtesy"].ToString();
          if (! sdr.IsDBNull(4)) {
            this.reportsTo        = sdr.GetInt32(4);
          }
        }
        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 string EmpID {
      get { return ID.ToString();  }
    }

    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 string FullName {
      get { return FirstName + " "
 + LastName; }
    }

    private string title;
    public String Title {
      get { return title; }
      set { title = value; }
    }

    private string titleOfCourtesy;
    public string Courtesy {
      get { return titleOfCourtesy; }
      set { titleOfCourtesy = value; }
    }

    private int    reportsTo;
    public int Supervisor {
      get { return reportsTo; }
      set { reportsTo = value; }
    }

    public bool Save () {
      // Implement persistence logic.
      return true;
    }

    public bool Delete () {
      // Implement delete logic.
      return true;
    }
  }

  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();

        ConnectionStringSettings cts = 
            ConfigurationManager.get_ConnectionStrings().
            get_Item("NorthwindConnection");
            //ConfigurationSettings.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();
                String id = row.get_Item("EmployeeID").ToString();
                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(Object
 anId) throws 
        NorthwindDataException, SqlException
    {
        if (anId.Equals("-1") || anId.Equals(DBNull.Value))
 {
            return new NorthwindEmployee();
        }
        else {
            return new NorthwindEmployee(anId);
        }
    } //GetEmployee

    public static void UpdateEmployeeInfo(NorthwindEmployee
 ne) throws 
        NorthwindDataException
    {
        boolean retval = ne.Save();
        if (!retval) {
            throw new NorthwindDataException("UpdateEmployee
 failed.");
        }
    } //UpdateEmployeeInfo

    public static void DeleteEmployee(NorthwindEmployee
 ne) throws 
        NorthwindDataException
    {
        boolean retval = ne.Delete();
        if (!retval) {
            throw new NorthwindDataException("DeleteEmployee
 failed.");
        }
    } //DeleteEmployee

    // And so on...
} //EmployeeLogic
   
public class NorthwindEmployee 
{
    public NorthwindEmployee() 
    {
        id = DBNull.Value;
        lastName = "";
        firstName = "";
        title = "";
        titleOfCourtesy = "";
        reportsTo =-1;
    } //NorthwindEmployee

    public NorthwindEmployee(Object anId) throws 
        NorthwindDataException ,SqlException
    {
        this.id = anId;
            

        SqlConnection conn = new SqlConnection(ConfigurationManager.
            get_ConnectionStrings().get_Item("NorthwindConnection").get_ConnectionString());
         SqlCommand sc =  new SqlCommand(
            " SELECT FirstName,LastName,Title,TitleOfCourtesy,ReportsTo "
 
            + " 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(anId.ToString());
         SqlDataReader sdr = null;
         
         try {
            conn.Open();
            sdr = sc.ExecuteReader();
            // Only loop 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();
                this.title = sdr.get_Item( "Title").ToString();
                this.titleOfCourtesy = sdr.get_Item( "TitleOfCourtesy").
                    ToString();
                if (!(sdr.IsDBNull(4))) {
                    this.reportsTo = sdr.GetInt32(4);
                }
            }
            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 String get_EmpID()
    {
        return id.ToString();
    } //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 

    /** @property 
     */
    public String get_FullName()
    {
        return get_FirstName() + " " + get_LastName();
    } //get_FullName

    private String title;
      
    /** @property 
     */
    public String get_Title()
    {
        return title;
    } //get_Title

    /** @property 
     */
    public void set_Title (String value)
    {
        title = value;
    } //set_Title 

    private String titleOfCourtesy;
      
    /** @property 
     */
    public String get_Courtesy()
    {
        return titleOfCourtesy;
    } //get_Courtesy

    /** @property 
     */
    public void set_Courtesy (String value)
    {
        titleOfCourtesy = value;
    } //set_Courtesy 

    private int reportsTo;
      
    /** @property 
     */
    public int get_Supervisor()
    {
        return reportsTo;
    }//get_Supervisor

    /** @property 
     */
    public void set_Supervisor (int
 value)
    {
        reportsTo = value;
    } //set_Supervisor 

    public boolean Save() 
    {
        // Implement persistence logic.
        return true;
    } //Save
      
    public boolean Delete() 
    {
        // Implement delete logic.
        return true;
    } //Delete
} //NorthwindEmployee

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



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS