gpt4 book ai didi

MySqlDataReader 在构建时给出错误

转载 作者:行者123 更新时间:2023-11-29 01:01:31 26 4
gpt4 key购买 nike

我在 VB.NET 中有一个函数,可以在启动主应用程序之前对 MySQL 数据库的用户进行身份验证。这是函数的代码:

    Public Function authConnect() As Boolean
Dim dbserver As String
Dim dbuser As String
Dim dbpass As String
dbserver = My.Settings.dbserver.ToString
dbuser = My.Settings.dbuser.ToString
dbpass = My.Settings.dbpass.ToString
conn = New MySqlConnection
myConnString = "server=" & dbserver & ";" & "user id=" & dbuser & ";" & "password=" & dbpass & ";" & "database=rtadmin"
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim myDataReader As New MySqlDataReader
Dim query As String

myCommand.Parameters.Add(New MySqlParameter("?Username", login_usr_txt.Text))
myCommand.Parameters.Add(New MySqlParameter("?Password", login_pass_txt.Text))
query = "select * from users where user = ?Username and passwd = ?Password"
conn.ConnectionString = myConnString
Try
conn.Open()
Try
myCommand.Connection = conn
myCommand.CommandText = query
myAdapter.SelectCommand = myCommand
myDataReader = myCommand.ExecuteReader
If myDataReader.HasRows() Then
MessageBox.Show("You've been logged in.", "RT Live! Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception

End Try
Catch ex As Exception

End Try
End Function

该功能尚未完成,在启动应用程序之前还需要做一些其他事情,因为我正在使用 MessageBox 来显示登录尝试的结果。

我得到的错误如下:

Error 1 'MySql.Data.MySqlClient.MySqlDataReader.Friend Sub New(cmd As MySql.Data.MySqlClient.MySqlCommand, statement As MySql.Data.MySqlClient.PreparableStatement, behavior As System.Data.CommandBehavior)' is not accessible in this context because it is 'Friend'. C:\Users\Mario\documents\visual studio 2010\Projects\Remote Techs Live!\Remote Techs Live!\Login.vb 43 13 Remote Techs Live!

有什么想法吗?

最佳答案

尝试创建一个 MySqlDataReader 然后将其丢弃是没有意义的!

首先,您这样做是为了尝试创建一个阅读器:

    Dim myDataReader As New MySqlDataReader

然后当你这样做的时候,你会试图把它扔掉:

    myDataReader = myCommand.ExecuteReader

只需从您的初始声明中删除 New 即可。我怀疑 MySqlDataReader 的构造函数不可公开访问。

关于MySqlDataReader 在构建时给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2819445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com