0

这是我的连接代码:

Imports System.Data.SqlClient
Public Class frm_edit_patient
    Dim con As New SqlConnection
    Private Sub frm_edit_patient_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        frm_dashboard.Enabled = True
        Me.Hide()
    End Sub
    Private Sub frm_edit_patient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1DataSet1.patients' table. You can move, or remove it, as needed.
        Me.PatientsTableAdapter.Fill(Me.Database1DataSet1.patients)
        frm_dashboard.Enabled = False
        Try
            Dim myConString As String = My.Settings.Database1ConnectionString
            con.ConnectionString = myConString
            con.Open()
            con.Close()
            MessageBox.Show("connected")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        frm_dashboard.Enabled = True
        Me.Hide()
    End Sub
End Class

但这给了我错误:

在此处输入图像描述

我正在使用绑定源进行数据库连接....

4

1 回答 1

1

Database.sdf 是 Sql Compact 数据库文件,而不是 Sql Server 目录名称。

你不需要SqlCeConnection使用SqlConnection

因此,您需要声明

Dim con As New SqlCeConnection

还请记住,您需要对程序集 System.Data.SqlServerCe 的引用
(在 System.Data.SqlServerCe.dll 中)

于 2012-08-23T10:42:22.017 回答