0

在过去的 4 周里,我一直在努力解决这个问题,但找不到我一直在绕圈子的答案。我在 con As New OleDb.OleDbConnection 和连接字符串和 ISAM 上遇到了多个错误

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim da As OleDb.OleDbDataAdapter
    Public sql As String
    Dim ds As New DataSet
    Dim dbPassword As String


        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "C:\Users\Edward\Desktop\Edward\DataBase Login Window\Users.mdb;Jet OLEDB:Database"

        con.ConnectionString = dbProvider & dbSource

        con.Open()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        sql = "SELECT * FROM users WHERE accUsername='" & TextBox1.Text & "'AND accPass='" & TextBox2.Text & "'"

        da = New OleDb.OleDbDataAdapter(sql, con)

        da.Fill(ds, "users")

        If ds.Tables("users").Rows.Count = 1 Then
            Dim isAdmin As Boolean = ds.Tables("users").Rows(0).Item(4)
            If isAdmin = True Then
                MsgBox("Logged in.")
                Form4.Show()
                Form4.Username = TextBox1.Text
                Form4.Password = TextBox2.Text
            ElseIf isAdmin = False Then
                MsgBox("Logged in user.")
                Form6.Show()
                Form6.Username = TextBox1.Text
                Form6.Password = TextBox2.Text
            End If
        Else
            MsgBox("Incorrect Username or Password")
        End If

        Me.Hide()

        ds.Clear()
        Me.Refresh()
    End Sub

    Private Sub createanaccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createanaccount.Click
        Form2.ShowDialog()

    End Sub
End Class
4

1 回答 1

0

在按钮中你应该设置 connectionString 这里是一个例子。

dim con as new SQLConnection/OLEDBConnection
con.ConnectionString="Provide your connection string"
con.open

我希望这肯定会解决您的问题

于 2013-06-07T07:59:24.900 回答