如何使用visual studio和sql compact创建数据连接?

时间:2016-01-19 10:43:47

标签: sql-server vb.net sql-server-ce

当我尝试执行此代码时,它会抛出一个错误,指出sql异常未处理。

    Dim cmdString = "Select * from STUDENT"

    connection = New SqlConnection("Data Source=gandharva.sdf")
    Dim command As SqlCommand

    command = New SqlCommand(cmdString, connection)

    connection.Open()

    Dim reader As SqlDataReader

    reader = command.ExecuteReader(CommandBehavior.CloseConnection)

    While reader.Read()


        Console.WriteLine(reader("studentname").ToString())
    End While
    Console.WriteLine("Press ENTER to exit")
    Console.ReadLine()
End Sub

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

您必须引用SQL Server Compact,System.Data.SqlServerCe的ADO.NET提供程序,并使用SqlCeConnection,SqlCeDataReader,SqlCeCommand等。