OleDbConnection 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 OleDbConnection 类的新实例。
重载
OleDbConnection() |
初始化 OleDbConnection 类的新实例。 |
OleDbConnection(String) |
使用指定的连接字符串初始化 OleDbConnection 类的新实例。 |
OleDbConnection()
- Source:
- DbConnectionHelper.cs
- Source:
- DbConnectionHelper.cs
初始化 OleDbConnection 类的新实例。
public:
OleDbConnection();
public OleDbConnection ();
Public Sub New ()
示例
以下示例创建并打开 。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
注解
创建新的 实例 OleDbConnection 时,读/写属性将设置为以下初始值,除非使用属性中的 ConnectionString 关联关键字专门设置它们。
属性 | 初始值 |
---|---|
ConnectionString | 空字符串 (“”) |
ConnectionTimeout | 15 |
Database | 空字符串 (“”) |
DataSource | 空字符串 (“”) |
只能使用 ConnectionString 属性更改这些属性的值。
另请参阅
适用于
OleDbConnection(String)
- Source:
- OleDbConnection.cs
- Source:
- OleDbConnection.cs
使用指定的连接字符串初始化 OleDbConnection 类的新实例。
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)
参数
- connectionString
- String
用于打开数据库的连接。
示例
以下示例创建并打开 。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
注解
创建新的 实例 OleDbConnection 时,读/写属性将设置为以下初始值,除非使用属性中的 ConnectionString 关联关键字专门设置它们。
属性 | 初始值 |
---|---|
ConnectionString | connectionString |
ConnectionTimeout | 15 |
Database | 空字符串 (“”) |
DataSource | 空字符串 (“”) |
只能使用 ConnectionString 属性更改这些属性的值。