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 Server カタログ名ではなく、Sql Compact データベース ファイルです。

を使用する必要はありSqlCeConnectionませんSqlConnection

したがって、宣言する必要があります

Dim con As New SqlCeConnection


また、アセンブリ System.Data.SqlServerCe (System.Data.SqlServerCe.dll 内)への参照が必要であることも忘れないでください。

于 2012-08-23T10:42:22.017 に答える