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 属性更改这些属性的值。
示例
下面的示例创建并打开一个 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();
}