我的Oledb DataAdapter.Fill代码是“缺少参数”

时间:2019-05-05 12:46:01

标签: vba visual-studio oledb

我正在尝试建立一个登录页面,该页面检查来自MS Access数据库的用户凭据。当我运行代码时,它说fill方法需要一个或多个参数。这是我正在使用的代码:

Public Class login
Public Shared dslogin As New DataSet
Public Shared con As New OleDb.OleDbConnection
Dim da1 As New OleDb.OleDbDataAdapter

'Global variables
Public Shared currentloginID As Integer = 0
Public Shared tbusername As TextBox
Public Shared tbpassword As TextBox

Private Function OpenDBConnection1()
    Dim directory1 As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
    Return "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source = " & directory1 & "\IEshiDBv1.accdb"
End Function

'login button
Private Sub btnLOGIN_Click(sender As Object, e As EventArgs) Handles btnLOGIN.Click

    Dim username As String = txtusername.Text
    Dim password As String = txtpassword.Text
    If username = "" Or password = "" Then
        MsgBox("Please enter log-in details")
        con.Close()
        Exit Sub
    Else
        Dim sqllogin As String = ("SELECT * FROM LoginRcrds WHERE LoginUserName = " & username)
        da1 = New OleDb.OleDbDataAdapter(sqllogin, con)
        da1.Fill(dslogin, "LoginCredentials")
        con.Close()
        Dim dtlogin As DataTable = dslogin.Tables("LoginCredentials")
        Dim rowlogin As DataRow
        For Each rowlogin In dtlogin.Rows
            If password = rowlogin("LoginPW") Then
                homepage.Show()
                Me.Hide()
                Exit For
            End If
        Next
        MsgBox("Incorrect log-in credentials. Please try again")
        Exit Sub
    End If

End Sub

'Onload subroutine
Private Sub login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    con.ConnectionString = (OpenDBConnection1())
    con.Open()
End Sub

结束班级

错误发生在

da1.Fill(dslogin, "LoginCredentials")

,错误消息显示“没有为一个或多个必需参数提供值。”

我在某处读到.Fill需要三个参数:(DataSet,RecordSet,TableName)。我从未尝试过这样做,因为我不了解RecordSet的含义。

编辑:我已经使用4.0 Oledb提供程序检查了另一个程序,并将其更改为12.0。出现相同的错误。看来Oledb 12.0的DataAdapter的Fill方法需要两个以上的参数。有人可以解释吗?

0 个答案:

没有答案