日期:2014-05-16  浏览次数:20412 次

VB连接扩展名为.sdf的SQL CE数据库
Imports System.Data.SqlServerCe

Public Module ConnCEDB

  Sub Main()
    Call Query()
  End Sub
	
  Sub Query()
		
    Dim cnnStr,sqlStr As String
    Dim conn As SqlCeConnection = Nothing
    Dim cmd As SqlCeCommand = Nothing
    Dim rdr As SqlCeDataReader = Nothing
		
    Try
        '建立数据库连接
        cnnStr="Data Source=Secured_db.sdf;Password=123456"
        conn = New SqlCeConnection(cnnStr)
        conn.Open()

        '查询数据库
        sqlStr="SELECT * FROM TRDX_HLDY_MASTER where HMA_HLDY_DATE='2012-10-8' and HMA_MKT_SRNO=1 and HMA_CLNDR_TYPE_INDC=0"
        cmd = New SqlCeCommand(sqlStr, conn)
        rdr = cmd.ExecuteReader

        '输出查询结果,如果存在多条记录打印True,否则打印False
        Console.WriteLine(rdr.Read)
    Catch ex As Exception
        Console.WriteLine(ex.Message.ToString)
    Finally
        '关闭数据库连接
        rdr.Close()
        conn.Close()
        rdr=Nothing
        cmd=Nothing
        conn=Nothing
    End Try

  End Sub
	
End Module

?

?

问题:程序报错“System.Data.SqlServerCe.SqlCeException: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8080. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details. ---> System.DllNotFoundException: Unable to load DLL 'sqlceme35.dll': 找不到指定的模块。”?

?

下载并安装SQL Server Compact 3.5 SP1,文件名为SSCERuntime-CHS-x86.msi或者SSCERuntime-CHS-x64.msi,下载地址http://www.microsoft.com/zh-cn/download/details.aspx?id=5821