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.

C#
public OleDbCommand();

Examples

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

C#
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();
    }
}

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

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

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.

C#
public OleDbCommand(string? cmdText);
C#
public OleDbCommand(string cmdText);

Parameters

cmdText
String

The text of the query.

Examples

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

C#
public void CreateMyOleDbCommand()
{
   string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
   OleDbCommand command = new OleDbCommand(queryString);
   command.CommandTimeout = 20;
}

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

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

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.

C#
public OleDbCommand(string? cmdText, System.Data.OleDb.OleDbConnection? connection);
C#
public OleDbCommand(string cmdText, System.Data.OleDb.OleDbConnection connection);

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.

C#
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();
    }
}

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

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

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.

C#
public OleDbCommand(string? cmdText, System.Data.OleDb.OleDbConnection? connection, System.Data.OleDb.OleDbTransaction? transaction);
C#
public OleDbCommand(string cmdText, System.Data.OleDb.OleDbConnection connection, System.Data.OleDb.OleDbTransaction transaction);

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.

C#
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();
    }
}

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

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)