【发布时间】:2018-11-03 10:33:16
【问题描述】:
我是 Stack Overflow 的新手,但无论如何我的代码都有问题。当我尝试运行程序并单击登录功能时,我在此语句中收到错误... Adapter.Fill(Table) 它说:FormatException 未处理。 mscorlib.dll 中出现“System.FormatException”类型的未处理异常附加信息:输入字符串的格式不正确。
Imports MySql.Data.MySqlClient
Public Class Login_page
Private Sub Login_page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CenterToScreen()
End Sub
Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MysqlConnection As New MySqlConnection("host=127.0.0.1; user=root; database = storage_db")
Dim Command As New MySqlCommand("SELECT * FROM `login_access` where username = @username and password = @password", MysqlConnection)
Command.Parameters.AddWithValue("@username", SqlDbType.VarChar).Value = TextBoxUsername.Text
Command.Parameters.AddWithValue("@password", SqlDbType.VarChar).Value = TextBoxPassword.Text
Dim Adapter As New MySqlDataAdapter(Command)
Dim Table As New DataTable()
Adapter.Fill(Table)
If Table.Rows.Count() <= 0 Then
MessageBox.Show("Invalid")
Else
MessageBox.Show("Login Successfully")
End If
End Sub
End Class
【问题讨论】:
-
我在回答中添加了一些信息,这些信息可能有助于您了解原始代码的实际行为。