Bagikan melalui


OleDbCommand Konstruktor

Definisi

Menginisialisasi instans baru kelas OleDbCommand.

Overload

OleDbCommand()

Menginisialisasi instans baru kelas OleDbCommand.

OleDbCommand(String)

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri.

OleDbCommand(String, OleDbConnection)

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri dan OleDbConnection.

OleDbCommand(String, OleDbConnection, OleDbTransaction)

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri, OleDbConnection, dan Transaction.

OleDbCommand()

Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs

Menginisialisasi instans baru kelas OleDbCommand.

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

Contoh

Contoh berikut membuat OleDbCommand dan mengatur beberapa propertinya.

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

Keterangan

Konstruktor dasar menginisialisasi semua bidang ke nilai defaultnya. Tabel berikut ini memperlihatkan nilai properti awal untuk instans OleDbCommand.

Properti Nilai Awal
CommandText string kosong ("")
CommandTimeout 30
CommandType Text
Connection null

Lihat juga

Berlaku untuk

OleDbCommand(String)

Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri.

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)

Parameter

cmdText
String

Teks kueri.

Contoh

Contoh berikut membuat OleDbCommand dan mengatur beberapa propertinya.

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

Keterangan

Tabel berikut ini memperlihatkan nilai properti awal untuk instans OleDbCommand.

Properti Nilai Awal
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection null

Lihat juga

Berlaku untuk

OleDbCommand(String, OleDbConnection)

Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri dan 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)

Parameter

cmdText
String

Teks kueri.

connection
OleDbConnection

Yang OleDbConnection mewakili koneksi ke sumber data.

Contoh

Contoh berikut membuat OleDbCommand dan mengatur beberapa propertinya.

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

Keterangan

Tabel berikut ini memperlihatkan nilai properti awal untuk instans OleDbCommand.

Properti Nilai Awal
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection OleDbConnection Baru yang merupakan nilai untuk connection parameter .

Anda dapat mengubah nilai untuk salah satu parameter ini dengan mengatur properti terkait.

Lihat juga

Berlaku untuk

OleDbCommand(String, OleDbConnection, OleDbTransaction)

Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs
Sumber:
OleDbCommand.cs

Menginisialisasi instans OleDbCommand baru kelas dengan teks kueri, OleDbConnection, dan 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)

Parameter

cmdText
String

Teks kueri.

connection
OleDbConnection

Yang OleDbConnection mewakili koneksi ke sumber data.

transaction
OleDbTransaction

Transaksi tempat OleDbCommand eksekusi.

Contoh

Contoh berikut membuat OleDbCommand dan mengatur beberapa propertinya.

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

Keterangan

Tabel berikut ini memperlihatkan nilai properti awal untuk instans OleDbCommand.

Properti Nilai Awal
CommandText cmdText
CommandTimeout 30
CommandType Text
Connection OleDbConnection Baru yang merupakan nilai untuk connection parameter .

Anda dapat mengubah nilai untuk salah satu parameter ini dengan mengatur properti terkait.

Lihat juga

Berlaku untuk