这是我编写的代码,它曾在访问级别显示 System.Data.Dataset 返回,但这不是我想要的。用户名是字符串,密码也是字符串,访问级别是整数。有没有更有效的替代方法?你也能解释一下为什么我会出错,这样我以后就不会遇到类似的事情了。提前致谢
[错误图片和访问打印的内容][1]
Public Class Login
Dim Access_level As Integer
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Parts.User' table. You can move, or remove it, as needed.
'Me.UserTableAdapter.Fill(Me.Parts.User)
End Sub
Public Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Oops ¯\_(ツ)_/¯ " + Err.Description(), MsgBoxStyle.OkOnly, "Enter Value")
Else
Try
Await getDataSet(TextBox1.Text, TextBox2.Text, Access_level)
Print(username)
Print(password)
If username = TextBox1.Text And password = TextBox2.Text Then
Dim Access As Integer = Access_level
Print(Access)
If Access = 1 Then
Me.Hide()
AdminMainMenu.Show()
Else
Me.Hide()
MainMenu.Show()
End If
End If
Catch ex As Exception
'MsgBox("Oops " + Err.Description(), MsgBoxStyle.OkOnly, "Failed to Open")
'MsgBox("Incorrect login details", MsgBoxStyle.OkOnly)
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End If
TextBox1.Clear()
TextBox2.Clear()
End Sub
Public Async Function getDataSet(username As String, password As String, Access_level As Integer) As Task(Of DataSet)
Return Await Task.Factory.StartNew(
Function()
Dim connectionString = "server=localhost; userid=root; password=; database=partstest1; CharSet=utf8;"
Dim commandText = "SELECT Username, Password, Accesslevel FROM `user` WHERE `Username` = '" & username & "' and `Password` = '" & SHA256(password) & "';"
Using connDB = New MySqlConnection(connectionString), objCmd = New MySqlCommand(), objAdpt = New MySqlDataAdapter()
connDB.Open()
objCmd.Connection = connDB
objCmd.CommandText = commandText
objCmd.CommandType = CommandType.Text
objAdpt.SelectCommand = objCmd
Dim objDs = New DataSet()
objAdpt.Fill(objDs)
Console.WriteLine(objDs)
Return objDs
End Using
End Function)
End Function
[1]: https://i.stack.imgur.com/g9CIj.png