Bewerken

Share via


DataObjectAttribute Constructors

Definition

Initializes a new instance of the DataObjectAttribute class.

Overloads

DataObjectAttribute()

Initializes a new instance of the DataObjectAttribute class.

DataObjectAttribute(Boolean)

Initializes a new instance of the DataObjectAttribute class and indicates whether an object is suitable for binding to an ObjectDataSource object.

DataObjectAttribute()

Source:
DataObjectAttribute.cs
Source:
DataObjectAttribute.cs
Source:
DataObjectAttribute.cs

Initializes a new instance of the DataObjectAttribute class.

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

Examples

The following code example demonstrates using the DataObjectAttribute() constructor.

[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

Remarks

The IsDataObject property is set to true when you use the DataObjectAttribute() constructor.

Applies to

DataObjectAttribute(Boolean)

Source:
DataObjectAttribute.cs
Source:
DataObjectAttribute.cs
Source:
DataObjectAttribute.cs

Initializes a new instance of the DataObjectAttribute class and indicates whether an object is suitable for binding to an ObjectDataSource object.

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

Parameters

isDataObject
Boolean

true if the object is suitable for binding to an ObjectDataSource object; otherwise, false.

Remarks

Use the DataObjectAttribute(Boolean) constructor to indicate to a design-time class such as the ObjectDataSourceDesigner class that an object should be excluded from the list of suitable objects for binding to an ObjectDataSource object.

The IsDataObject property is set to the value of the isDataObject parameter.

Applies to