Bagikan melalui


OleDbConnection.ChangeDatabase(String) Metode

Definisi

Mengubah database saat ini untuk yang terbuka OleDbConnection.

public:
 override void ChangeDatabase(System::String ^ value);
public:
 virtual void ChangeDatabase(System::String ^ value);
public override void ChangeDatabase (string value);
public void ChangeDatabase (string value);
override this.ChangeDatabase : string -> unit
abstract member ChangeDatabase : string -> unit
override this.ChangeDatabase : string -> unit
Public Overrides Sub ChangeDatabase (value As String)
Public Sub ChangeDatabase (value As String)

Parameter

value
String

Nama database.

Penerapan

Pengecualian

Nama database tidak valid.

Koneksi tidak terbuka.

Tidak dapat mengubah database.

Contoh

Contoh berikut membuat OleDbConnection dan menampilkan beberapa properti baca-saja.

static void ChangeDatabaseConnection(string connectionString)
{
   using (OleDbConnection connection = new OleDbConnection(connectionString))
   {
      try
      {
         connection.Open();
         Console.WriteLine("ServerVersion: {0} \nDatabase: {1}",
             connection.ServerVersion, connection.Database);

         connection.ChangeDatabase("Northwind");
         Console.WriteLine("ServerVersion: {0} \nDatabase: {1}",
            connection.ServerVersion, connection.Database);
      }
      catch (Exception ex)
      {
         Console.WriteLine(ex.Message);
      }
      // The connection is automatically closed when the
      // code exits the using block.
   }
}
Public Sub ChangeDatabaseConnection(ByVal connectionString As String)

   Using connection As New OleDbConnection(connectionString)
      Try
         connection.Open()
         Console.WriteLine("Server Version: {0} Database: {1}", _
             connection.ServerVersion, connection.Database)
         connection.ChangeDatabase("Northwind")
         Console.WriteLine("Server Version: {0} Database: {1}", _
            connection.ServerVersion, connection.Database)

      Catch ex As Exception
         Console.WriteLine(ex.Message)
      End Try
      ' The connection is automatically closed when the
      ' code exits the Using block.
   End Using
End Sub

Keterangan

Nilai yang database disediakan dalam parameter harus berupa nama database yang valid. Parameter database tidak boleh berisi nilai null, string kosong, atau string hanya dengan karakter kosong.

Berlaku untuk

Lihat juga