0

我正在尝试访问 Sql Server Compact 数据库。这是一个 clickonce 应用程序,所以如果可以在安装应用程序时创建数据库,我希望它。

我明白了,当应用程序启动时,数据库是使用 SqlCeEngine、SqlCeConnection 等创建的。

但是,以这种方式查询和插入很复杂,所以我希望让它与 ADODB 一起使用。

    Dim MyCn As New ADODB.Connection
    MyCn.Provider = "Microsoft.SQLSERVER.CE.OLEDB.3.5"
    MyCn.ConnectionString = My.Settings.LocalConnectionString
    MyCn.Open()

    Dim rSelect As New ADODB.Recordset

    With rSelect
        .Open("Select wID, DirPath, Children From Watches Where DirPath like '" & dialog.SelectedPath & "'", MyCn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
        If .EOF Then
            .AddNew()
            .Fields!DirPath.Value = dialog.SelectedPath
            .Fields!Children.Value = True
            .Update()
        End If
        .Close()
    End With

但我收到一个错误:

In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

或者,我不介意学习如何使用 LINQ to SQL,因为 3.5 支持它,但我还没有找到如何连接到程序第一次启动之前可能不存在的数据库,这意味着我不能使用数据库向导。

4

3 回答 3

0

这只是一个意见,为什么不使用实体框架: 是一种制作连接手册的方法这只是一个意见,希望对您有所帮助...

于 2012-09-11T22:49:12.367 回答
0

您正在使用 SQL Server CE,本文是您的应用程序的
演练 http://blogs.msdn.com/b/stevelasker/archive/2008/02/11/stored-procedures-and-sql-server -compact-the-great-debate.aspx

于 2012-09-12T08:02:51.723 回答
0

找到了一些使用 LINQ to SQL 的教程。
它不像 ADODB 在常规 SQL Server 中那样易于使用,因为您必须为每个表创建类,但这还不错。

于 2012-09-26T13:32:47.463 回答