共用方式為


DataObjectAttribute 建構函式

定義

初始化 DataObjectAttribute 類別的新執行個體。

多載

DataObjectAttribute()

初始化 DataObjectAttribute 類別的新執行個體。

DataObjectAttribute(Boolean)

初始化 DataObjectAttribute 類別的新執行個體,並指出物件是否適合繫結至 ObjectDataSource 物件。

DataObjectAttribute()

來源:
DataObjectAttribute.cs
來源:
DataObjectAttribute.cs
來源:
DataObjectAttribute.cs

初始化 DataObjectAttribute 類別的新執行個體。

public:
 DataObjectAttribute();
public DataObjectAttribute ();
Public Sub New ()

範例

下列程式代碼範例示範如何使用 建 DataObjectAttribute() 構函式。

[DataObjectAttribute]
public class NorthwindData
{  
  public NorthwindData() {}

  [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  public static IEnumerable GetAllEmployees()
  {
    AccessDataSource ads = new AccessDataSource();
    ads.DataSourceMode = SqlDataSourceMode.DataReader;
    ads.DataFile = "~//App_Data//Northwind.mdb";
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees";
    return ads.Select(DataSourceSelectArguments.Empty);
  }

  // Delete the Employee by ID.
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  public void DeleteEmployeeByID(int employeeID)
  {
    throw new Exception("The value passed to the delete method is "
                         + employeeID.ToString());
  }
}
<DataObjectAttribute()> _
Public Class NorthwindData

  <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
  Public Shared Function GetAllEmployees() As IEnumerable
    Dim ads As New AccessDataSource()
    ads.DataSourceMode = SqlDataSourceMode.DataReader
    ads.DataFile = "~/App_Data/Northwind.mdb"
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees"
    Return ads.Select(DataSourceSelectArguments.Empty)
  End Function 'GetAllEmployees

  ' Delete the Employee by ID.
  <DataObjectMethodAttribute(DataObjectMethodType.Delete, True)> _
  Public Sub DeleteEmployeeByID(ByVal employeeID As Integer)
    Throw New Exception("The value passed to the delete method is " + employeeID.ToString())
  End Sub

End Class

備註

當您使用建構函式時,屬性 IsDataObject 會設定為 trueDataObjectAttribute()

適用於

DataObjectAttribute(Boolean)

來源:
DataObjectAttribute.cs
來源:
DataObjectAttribute.cs
來源:
DataObjectAttribute.cs

初始化 DataObjectAttribute 類別的新執行個體,並指出物件是否適合繫結至 ObjectDataSource 物件。

public:
 DataObjectAttribute(bool isDataObject);
public DataObjectAttribute (bool isDataObject);
new System.ComponentModel.DataObjectAttribute : bool -> System.ComponentModel.DataObjectAttribute
Public Sub New (isDataObject As Boolean)

參數

isDataObject
Boolean

如果物件適合繫結至 ObjectDataSource 物件,則為 true,否則為 false

備註

使用 建 DataObjectAttribute(Boolean) 構函式向設計時間類別表示,例如 ObjectDataSourceDesigner 應該從適合物件清單中排除對象的類別,以便系結至 ObjectDataSource 物件。

屬性 IsDataObject 會設定為 參數的值 isDataObject

適用於