Parameter 建構函式

定義

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

多載

Parameter()

初始化 Parameter 類別預設的新執行個體。

Parameter(String)

使用指定的名稱來初始化 Parameter 類別的新執行個體。

Parameter(Parameter)

使用原始、指定之執行個體的值,初始化 Parameter 類別的新執行個體。

Parameter(String, DbType)

使用指定的名稱和資料庫型別,初始化 Parameter 類別的新執行個體。

Parameter(String, TypeCode)

使用指定的名稱和型別來初始化 Parameter 類別的新執行個體。

Parameter(String, DbType, String)

使用指定的名稱、指定的資料庫型別,以及其 Parameter 屬性的指定值,初始化 DefaultValue 類別的新執行個體。

Parameter(String, TypeCode, String)

使用指定的名稱、指定的型別和為其 Parameter 屬性指定的字串來初始化 DefaultValue 類別的新執行個體。

Parameter()

初始化 Parameter 類別預設的新執行個體。

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

備註

Parameter使用建構函式建立的物件 Parameter() 會使用其所有屬性的預設值初始化。 屬性會初始化為 、 TypeCode.Object 屬性初始化為 、 Direction 屬性 Input 初始化為 ,而且 DefaultValue 屬性會初始化為 nullNameTypeString.Empty

適用於

Parameter(String)

使用指定的名稱來初始化 Parameter 類別的新執行個體。

public:
 Parameter(System::String ^ name);
public Parameter (string name);
new System.Web.UI.WebControls.Parameter : string -> System.Web.UI.WebControls.Parameter
Public Sub New (name As String)

參數

name
String

參數名稱。

範例

下列程式碼範例示範如何從擴充 Parameter 類別的 類別呼叫 Parameter(String) 建構函式,以初始化 Name 實例的 屬性。 此程式碼範例是類別概觀所提供較大範例的 Parameter 一部分。

// The StaticParameter(string, object) constructor
// initializes the DataValue property and calls the
// Parameter(string) constructor to initialize the Name property.
public StaticParameter(string name, object value) : base(name) {
  DataValue = value;
}
' The StaticParameter(string, object) constructor
' initializes the DataValue property and calls the
' Parameter(string) constructor to initialize the Name property.
 Public Sub New(name As String, value As Object)
    MyBase.New(name)
    DataValue = value
 End Sub

備註

Parameter使用建構函式建立的 Parameter(String) 物件會使用其其他屬性的指定 name 和預設值初始化。 屬性會初始化為 ,屬性 Type 會初始化為 Input ,而 DefaultValue 屬性則會初始化為 nullDirectionTypeCode.Object

另請參閱

適用於

Parameter(Parameter)

使用原始、指定之執行個體的值,初始化 Parameter 類別的新執行個體。

protected:
 Parameter(System::Web::UI::WebControls::Parameter ^ original);
protected Parameter (System.Web.UI.WebControls.Parameter original);
new System.Web.UI.WebControls.Parameter : System.Web.UI.WebControls.Parameter -> System.Web.UI.WebControls.Parameter
Protected Sub New (original As Parameter)

參數

original
Parameter

Parameter 執行個體,初始化目前執行個體的起源。

範例

下列程式碼範例示範如何從擴充 Parameter 類別的 類別呼叫 Parameter(Parameter) 建構函式,以實作 類別的正確物件複製行為。 此程式碼範例是類別概觀所提供較大範例的 Parameter 一部分。

// The StaticParameter copy constructor is provided to ensure that
// the state contained in the DataValue property is copied to new
// instances of the class.
protected StaticParameter(StaticParameter original) : base(original) {
  DataValue = original.DataValue;
}

// The Clone method is overridden to call the
// StaticParameter copy constructor, so that the data in
// the DataValue property is correctly transferred to the
// new instance of the StaticParameter.
protected override Parameter Clone() {
  return new StaticParameter(this);
}
' The StaticParameter copy constructor is provided to ensure that
' the state contained in the DataValue property is copied to new
' instances of the class.
Protected Sub New(original As StaticParameter)
   MyBase.New(original)
   DataValue = original.DataValue
End Sub

' The Clone method is overridden to call the
' StaticParameter copy constructor, so that the data in
' the DataValue property is correctly transferred to the
' new instance of the StaticParameter.
Protected Overrides Function Clone() As Parameter
   Return New StaticParameter(Me)
End Function

備註

Parameter(Parameter) 構函式是 protected 用來複製實例的 Parameter 複製建構函式。 、 TypeDefaultValueDirectionConvertEmptyStringToNull 屬性的值 Name 全都會傳輸至新的實例。

另請參閱

適用於

Parameter(String, DbType)

使用指定的名稱和資料庫型別,初始化 Parameter 類別的新執行個體。

public:
 Parameter(System::String ^ name, System::Data::DbType dbType);
public Parameter (string name, System.Data.DbType dbType);
new System.Web.UI.WebControls.Parameter : string * System.Data.DbType -> System.Web.UI.WebControls.Parameter
Public Sub New (name As String, dbType As DbType)

參數

name
String

參數名稱。

dbType
DbType

參數的資料庫型別。

備註

Parameter使用建構函式建立的物件 Parameter(String, DbType) 會以指定的 namedbType 參數初始化,並使用其他屬性的預設值初始化。 屬性 Direction 會初始化為 Input ,而且 DefaultValue 屬性會初始化為 null

適用於

Parameter(String, TypeCode)

使用指定的名稱和型別來初始化 Parameter 類別的新執行個體。

public:
 Parameter(System::String ^ name, TypeCode type);
public Parameter (string name, TypeCode type);
new System.Web.UI.WebControls.Parameter : string * TypeCode -> System.Web.UI.WebControls.Parameter
Public Sub New (name As String, type As TypeCode)

參數

name
String

參數名稱。

type
TypeCode

TypeCode,描述參數的型別。

範例

下列程式碼範例示範如何從擴充 Parameter 類別的 類別呼叫 Parameter(String, TypeCode) 建構函式,以初始化 Name 實例的 和 Type 屬性。 此程式碼範例是類別概觀所提供較大範例的 Parameter 一部分。

// The StaticParameter(string, TypeCode, object) constructor
// initializes the DataValue property and calls the
// Parameter(string, TypeCode) constructor to initialize the Name and
// Type properties.
public StaticParameter(string name, TypeCode type, object value) : base(name, type) {
  DataValue = value;
}
' The StaticParameter(string, TypeCode, object) constructor
' initializes the DataValue property and calls the
' Parameter(string, TypeCode) constructor to initialize the Name and
' Type properties.
Public Sub New(name As String, type As TypeCode, value As Object)
   MyBase.New(name, type)
   DataValue = value
End Sub

備註

Parameter使用建構函式建立的物件 Parameter(String, TypeCode) 會使用指定的 nametype 參數初始化,以及其他屬性的預設值。 屬性 Direction 會初始化為 Input ,而且 DefaultValue 屬性會初始化為 null

另請參閱

適用於

Parameter(String, DbType, String)

使用指定的名稱、指定的資料庫型別,以及其 Parameter 屬性的指定值,初始化 DefaultValue 類別的新執行個體。

public:
 Parameter(System::String ^ name, System::Data::DbType dbType, System::String ^ defaultValue);
public Parameter (string name, System.Data.DbType dbType, string defaultValue);
new System.Web.UI.WebControls.Parameter : string * System.Data.DbType * string -> System.Web.UI.WebControls.Parameter
Public Sub New (name As String, dbType As DbType, defaultValue As String)

參數

name
String

Parameter 執行個體的名稱。

dbType
DbType

Parameter 執行個體的資料庫型別。

defaultValue
String

如果在呼叫 Parameter 時,Parameter 繫結至尚未初始化的值,則為 Evaluate(HttpContext, Control) 執行個體的預設值。

備註

實例 DirectionParameter 屬性會初始化為 Input

適用於

Parameter(String, TypeCode, String)

使用指定的名稱、指定的型別和為其 Parameter 屬性指定的字串來初始化 DefaultValue 類別的新執行個體。

public:
 Parameter(System::String ^ name, TypeCode type, System::String ^ defaultValue);
public Parameter (string name, TypeCode type, string defaultValue);
new System.Web.UI.WebControls.Parameter : string * TypeCode * string -> System.Web.UI.WebControls.Parameter
Public Sub New (name As String, type As TypeCode, defaultValue As String)

參數

name
String

參數名稱。

type
TypeCode

TypeCode,描述參數的型別。

defaultValue
String

如果這個 Parameter 繫結的值,在呼叫 Evaluate(HttpContext, Control) 時尚未被初始化,則字串會做為參數的預設值。

範例

下列程式碼範例示範如何使用 建 Parameter(String, TypeCode, String) 構函式,在呼叫 Update 方法之前,將更新參數物件新增至 UpdateParameters 控制項的 AccessDataSource 集合。

<script runat="server">
private void UpdateRecords(Object source, EventArgs e)
{
  // This method is an example of batch updating using a
  // data source control. The method iterates through the rows
  // of the GridView, extracts each CheckBox from the row and, if
  // the CheckBox is checked, updates data by calling the Update
  // method of the data source control, adding required parameters
  // to the UpdateParameters collection.
  CheckBox cb;
  foreach(GridViewRow row in this.GridView1.Rows) {
    cb = (CheckBox) row.Cells[0].Controls[1];
    if(cb.Checked) {
      string oid = (string) row.Cells[1].Text;
      MyAccessDataSource.UpdateParameters.Add(new Parameter("date",TypeCode.DateTime,DateTime.Now.ToString()));
      MyAccessDataSource.UpdateParameters.Add(new Parameter("orderid",TypeCode.String,oid));
      MyAccessDataSource.Update();
      MyAccessDataSource.UpdateParameters.Clear();
    }
  }
}
</script>
<script runat="server">
Private Sub UpdateRecords(source As Object, e As EventArgs)

  ' This method is an example of batch updating using a
  ' data source control. The method iterates through the rows
  ' of the GridView, extracts each CheckBox from the row and, if
  ' the CheckBox is checked, updates data by calling the Update
  ' method of the data source control, adding required parameters
  ' to the UpdateParameters collection.

  Dim cb As CheckBox
  Dim row As GridViewRow

  For Each row In GridView1.Rows

    cb = CType(row.Cells(0).Controls(1), CheckBox)
    If cb.Checked Then

      Dim oid As String
      oid = CType(row.Cells(1).Text, String)

      Dim param1 As New Parameter("date", TypeCode.DateTime, DateTime.Now.ToString())
      MyAccessDataSource.UpdateParameters.Add(param1)

      Dim param2 As New Parameter("orderid", TypeCode.String, oid)
      MyAccessDataSource.UpdateParameters.Add(param2)

      MyAccessDataSource.Update()
      MyAccessDataSource.UpdateParameters.Clear()
    End If
  Next
End Sub ' UpdateRecords
</script>

備註

Parameter使用建構函式建立的物件 Parameter(String, TypeCode, String) 會以指定的 name 參數和 type 參數初始化,並指派 DefaultValue 屬性值。 Direction 屬性會初始化為 Input

另請參閱

適用於