Bagikan melalui


OleDbCommand.Connection Properti

Definisi

Mendapatkan atau mengatur yang OleDbConnection digunakan oleh instans ini dari OleDbCommand.

public:
 property System::Data::OleDb::OleDbConnection ^ Connection { System::Data::OleDb::OleDbConnection ^ get(); void set(System::Data::OleDb::OleDbConnection ^ value); };
public System.Data.OleDb.OleDbConnection? Connection { get; set; }
[System.Data.DataSysDescription("DbCommand_Connection")]
public System.Data.OleDb.OleDbConnection Connection { get; set; }
public System.Data.OleDb.OleDbConnection Connection { get; set; }
member this.Connection : System.Data.OleDb.OleDbConnection with get, set
[<System.Data.DataSysDescription("DbCommand_Connection")>]
member this.Connection : System.Data.OleDb.OleDbConnection with get, set
Public Property Connection As OleDbConnection

Nilai Properti

Koneksi ke sumber data. Nilai defaultnya adalah null.

Atribut

Pengecualian

Properti Connection diubah saat transaksi sedang berlangsung.

Contoh

Contoh berikut membuat OleDbCommand dan mengatur beberapa propertinya.

public void CreateOleDbCommand()
{
   string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
   OleDbCommand command = new OleDbCommand(queryString);
   command.Connection = new OleDbConnection
      ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB");
   command.CommandTimeout = 20;
}
Public Sub CreateOleDbCommand()
    Dim queryString As String = _
       "SELECT * FROM Categories ORDER BY CategoryID"
    Dim command As New OleDbCommand(queryString)
    command.Connection = New OleDbConnection _
       ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB")
    command.CommandTimeout = 20
End Sub

Keterangan

Anda tidak dapat mengatur Connectionproperti , CommandType dan CommandText jika koneksi saat ini melakukan operasi eksekusi atau pengambilan.

Jika Anda mengatur Connection saat transaksi sedang berlangsung dan Transaction properti tidak null, InvalidOperationException akan dihasilkan. Transaction Jika properti tidak null dan transaksi telah diterapkan atau digulung balik, Transaction diatur ke null.

Berlaku untuk

Lihat juga