共用方式為


OleDbCommand 建構函式

定義

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

多載

OleDbCommand()

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

OleDbCommand(String)

使用查詢的文字,初始化 OleDbCommand 類別的新執行個體。

OleDbCommand(String, OleDbConnection)

使用查詢的文字和 OleDbConnection 初始化 OleDbCommand 類別的新執行個體。

OleDbCommand(String, OleDbConnection, OleDbTransaction)

使用查詢的文字、OleDbConnectionTransaction,初始化 OleDbCommand 類別的新執行個體。

OleDbCommand()

來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs

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

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

範例

下列範例會 OleDbCommand 建立 並設定其部分屬性。

public void CreateReader(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        command.CommandTimeout = 20;

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}
Public Sub CreateReader(ByVal connectionString As String, _
    ByVal queryString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)
        command.CommandTimeout = 20

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

備註

基底建構函式會將所有字段初始化為其預設值。 下表顯示 實例 OleDbCommand的初始屬性值。

屬性 初始值
CommandText 空字串 (“”)
CommandTimeout 30
CommandType Text
Connection null

另請參閱

適用於

OleDbCommand(String)

來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs

使用查詢的文字,初始化 OleDbCommand 類別的新執行個體。

public:
 OleDbCommand(System::String ^ cmdText);
public OleDbCommand (string? cmdText);
public OleDbCommand (string cmdText);
new System.Data.OleDb.OleDbCommand : string -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String)

參數

cmdText
String

查詢的文字。

範例

下列範例會 OleDbCommand 建立 並設定其部分屬性。

public void CreateMyOleDbCommand()
{
   string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
   OleDbCommand command = new OleDbCommand(queryString);
   command.CommandTimeout = 20;
}
Public Sub CreateMyOleDbCommand()
    Dim queryString As String = "SELECT * FROM Categories ORDER BY CategoryID"
    Dim command As New OleDbCommand(queryString)
    command.CommandTimeout = 20
End Sub

備註

下表顯示 實例 OleDbCommand的初始屬性值。

屬性 初始值
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection null

另請參閱

適用於

OleDbCommand(String, OleDbConnection)

來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs

使用查詢的文字和 OleDbConnection 初始化 OleDbCommand 類別的新執行個體。

public:
 OleDbCommand(System::String ^ cmdText, System::Data::OleDb::OleDbConnection ^ connection);
public OleDbCommand (string? cmdText, System.Data.OleDb.OleDbConnection? connection);
public OleDbCommand (string cmdText, System.Data.OleDb.OleDbConnection connection);
new System.Data.OleDb.OleDbCommand : string * System.Data.OleDb.OleDbConnection -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String, connection As OleDbConnection)

參數

cmdText
String

查詢的文字。

connection
OleDbConnection

OleDbConnection 表示資料來源的連接。

範例

下列範例會 OleDbCommand 建立 並設定其部分屬性。

public void CreateReader(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        command.CommandTimeout = 20;

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}
Public Sub CreateReader(ByVal connectionString As String, _
    ByVal queryString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)
        command.CommandTimeout = 20

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

備註

下表顯示 實例 OleDbCommand的初始屬性值。

屬性 初始值
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection 新的 OleDbConnection ,這是參數的值 connection

您可以藉由設定相關屬性來變更這些參數的值。

另請參閱

適用於

OleDbCommand(String, OleDbConnection, OleDbTransaction)

來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs
來源:
OleDbCommand.cs

使用查詢的文字、OleDbConnectionTransaction,初始化 OleDbCommand 類別的新執行個體。

public:
 OleDbCommand(System::String ^ cmdText, System::Data::OleDb::OleDbConnection ^ connection, System::Data::OleDb::OleDbTransaction ^ transaction);
public OleDbCommand (string? cmdText, System.Data.OleDb.OleDbConnection? connection, System.Data.OleDb.OleDbTransaction? transaction);
public OleDbCommand (string cmdText, System.Data.OleDb.OleDbConnection connection, System.Data.OleDb.OleDbTransaction transaction);
new System.Data.OleDb.OleDbCommand : string * System.Data.OleDb.OleDbConnection * System.Data.OleDb.OleDbTransaction -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String, connection As OleDbConnection, transaction As OleDbTransaction)

參數

cmdText
String

查詢的文字。

connection
OleDbConnection

OleDbConnection 表示資料來源的連接。

transaction
OleDbTransaction

其中執行 OleDbCommand 的交易。

範例

下列範例會 OleDbCommand 建立 並設定其部分屬性。

public void CreateReader(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        command.CommandTimeout = 20;

        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}
Public Sub CreateReader(ByVal connectionString As String, _
    ByVal queryString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)
        command.CommandTimeout = 20

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

備註

下表顯示 實例 OleDbCommand的初始屬性值。

屬性 初始值
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection 新的 OleDbConnection ,這是參數的值 connection

您可以藉由設定相關屬性來變更這些參數的值。

另請參閱

適用於