共用方式為


SqlCeConnection 建構函式 (String)

使用指定的連接字串初始化 SqlCeConnection 類別的新執行個體。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
Public Sub New ( _
    connectionString As String _
)
'用途
Dim connectionString As String

Dim instance As New SqlCeConnection(connectionString)
public SqlCeConnection(
    string connectionString
)
public:
SqlCeConnection(
    String^ connectionString
)
new : 
        connectionString:string -> SqlCeConnection
public function SqlCeConnection(
    connectionString : String
)

參數

  • connectionString
    型別:System.String
    用來開啟資料庫的連接。

備註

在建立 SqlCeConnection 的新執行個體時,讀取/寫入屬性會設定為下列的初始值,除非藉由使用 ConnectionString 屬性中與其相關的關鍵字特別加以設定。

屬性

初始值

ConnectionString

connectionString

DataSource

空字串 ("")

您只能藉由使用 ConnectionString 屬性來變更這些屬性的值。

範例

下列範例會建立並開啟 SqlCeConnection

Dim conn As SqlCeConnection = Nothing

Try
    conn = New SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'")
    conn.Open()

    Dim cmd As SqlCeCommand = conn.CreateCommand()
    cmd.CommandText = "INSERT INTO Customers ([Customer ID], [Company Name]) Values('NWIND', 'Northwind Traders')"

    cmd.ExecuteNonQuery()
Finally
    conn.Close()
End Try
SqlCeConnection conn = null;

try
{
    conn = new SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'");
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandText = "INSERT INTO Customers ([Customer ID], [Company Name]) Values('NWIND', 'Northwind Traders')";

    cmd.ExecuteNonQuery();
}
finally
{
    conn.Close();
}

請參閱

參考

SqlCeConnection 類別

SqlCeConnection 多載

System.Data.SqlServerCe 命名空間