Modifica

Condividi tramite


OleDbCommand Constructors

Definition

Initializes a new instance of the OleDbCommand class.

Overloads

OleDbCommand()

Initializes a new instance of the OleDbCommand class.

OleDbCommand(String)

Initializes a new instance of the OleDbCommand class with the text of the query.

OleDbCommand(String, OleDbConnection)

Initializes a new instance of the OleDbCommand class with the text of the query and an OleDbConnection.

OleDbCommand(String, OleDbConnection, OleDbTransaction)

Initializes a new instance of the OleDbCommand class with the text of the query, an OleDbConnection, and the Transaction.

OleDbCommand()

Source:
OleDbCommand.cs
Source:
OleDbCommand.cs
Source:
OleDbCommand.cs

Initializes a new instance of the OleDbCommand class.

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

Examples

The following example creates an OleDbCommand and sets some of its properties.

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

Remarks

The base constructor initializes all fields to their default values. The following table shows initial property values for an instance of OleDbCommand.

Properties Initial Value
CommandText empty string ("")
CommandTimeout 30
CommandType Text
Connection null

See also

Applies to

OleDbCommand(String)

Source:
OleDbCommand.cs
Source:
OleDbCommand.cs
Source:
OleDbCommand.cs

Initializes a new instance of the OleDbCommand class with the text of the query.

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)

Parameters

cmdText
String

The text of the query.

Examples

The following example creates an OleDbCommand and sets some of its properties.

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

Remarks

The following table shows initial property values for an instance of OleDbCommand.

Properties Initial Value
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection null

See also

Applies to

OleDbCommand(String, OleDbConnection)

Source:
OleDbCommand.cs
Source:
OleDbCommand.cs
Source:
OleDbCommand.cs

Initializes a new instance of the OleDbCommand class with the text of the query and an OleDbConnection.

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)

Parameters

cmdText
String

The text of the query.

connection
OleDbConnection

An OleDbConnection that represents the connection to a data source.

Examples

The following example creates an OleDbCommand and sets some of its properties.

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

Remarks

The following table shows initial property values for an instance of OleDbCommand.

Properties Initial Value
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection A new OleDbConnection that is the value for the connection parameter.

You can change the value for any of these parameters by setting the related property.

See also

Applies to

OleDbCommand(String, OleDbConnection, OleDbTransaction)

Source:
OleDbCommand.cs
Source:
OleDbCommand.cs
Source:
OleDbCommand.cs

Initializes a new instance of the OleDbCommand class with the text of the query, an OleDbConnection, and the Transaction.

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)

Parameters

cmdText
String

The text of the query.

connection
OleDbConnection

An OleDbConnection that represents the connection to a data source.

transaction
OleDbTransaction

The transaction in which the OleDbCommand executes.

Examples

The following example creates an OleDbCommand and sets some of its properties.

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

Remarks

The following table shows initial property values for an instance of OleDbCommand.

Properties Initial Value
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection A new OleDbConnection that is the value for the connection parameter.

You can change the value for any of these parameters by setting the related property.

See also

Applies to