OleDbConnection Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas OleDbConnection.
Overload
OleDbConnection() |
Menginisialisasi instans baru kelas OleDbConnection. |
OleDbConnection(String) |
Menginisialisasi instans OleDbConnection baru kelas dengan string koneksi yang ditentukan. |
OleDbConnection()
- Sumber:
- DbConnectionHelper.cs
- Sumber:
- DbConnectionHelper.cs
- Sumber:
- DbConnectionHelper.cs
- Sumber:
- DbConnectionHelper.cs
- Sumber:
- DbConnectionHelper.cs
Menginisialisasi instans baru kelas OleDbConnection.
public:
OleDbConnection();
public OleDbConnection ();
Public Sub New ()
Contoh
Contoh berikut membuat dan membuka OleDbConnection.
static void OpenConnection(string connectionString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
try
{
connection.Open();
Console.WriteLine("DataSource: {0} \nDatabase: {1}",
connection.DataSource, connection.Database);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}
Public Sub OpenConnection(ByVal connectionString As String)
Using connection As New OleDbConnection(connectionString)
Try
connection.Open()
Console.WriteLine("DataSource: {0} Database: {1}", _
connection.DataSource, 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
Saat instans OleDbConnection baru dibuat, properti baca/tulis diatur ke nilai awal berikut kecuali secara khusus diatur menggunakan kata kunci terkait di ConnectionString properti .
Properti | Nilai awal |
---|---|
ConnectionString | string kosong ("") |
ConnectionTimeout | 15 |
Database | string kosong ("") |
DataSource | string kosong ("") |
Anda dapat mengubah nilai untuk properti ini hanya dengan menggunakan ConnectionString properti .
Lihat juga
Berlaku untuk
OleDbConnection(String)
- Sumber:
- OleDbConnection.cs
- Sumber:
- OleDbConnection.cs
- Sumber:
- OleDbConnection.cs
- Sumber:
- OleDbConnection.cs
- Sumber:
- OleDbConnection.cs
Menginisialisasi instans OleDbConnection baru kelas dengan string koneksi yang ditentukan.
public:
OleDbConnection(System::String ^ connectionString);
public OleDbConnection (string? connectionString);
public OleDbConnection (string connectionString);
new System.Data.OleDb.OleDbConnection : string -> System.Data.OleDb.OleDbConnection
Public Sub New (connectionString As String)
Parameter
- connectionString
- String
Koneksi yang digunakan untuk membuka database.
Contoh
Contoh berikut membuat dan membuka OleDbConnection.
static void OpenConnection(string connectionString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
try
{
connection.Open();
Console.WriteLine("DataSource: {0} \nDatabase: {1}",
connection.DataSource, connection.Database);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}
Public Sub OpenConnection(ByVal connectionString As String)
Using connection As New OleDbConnection(connectionString)
Try
connection.Open()
Console.WriteLine("DataSource: {0} Database: {1}", _
connection.DataSource, 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
Saat instans OleDbConnection baru dibuat, properti baca/tulis diatur ke nilai awal berikut kecuali secara khusus diatur menggunakan kata kunci terkait di ConnectionString properti .
Properti | Nilai awal |
---|---|
ConnectionString | connectionString |
ConnectionTimeout | 15 |
Database | string kosong ("") |
DataSource | string kosong ("") |
Anda dapat mengubah nilai untuk properti ini hanya dengan menggunakan ConnectionString properti .