考虑以下代码:
answer = today.AddDays(356)
Dim command1 As New MySqlCommand("Insert into UserScanner (Username,Password,Address,Contact,SubStart,SubEnd,Active) VALUES('" & txtbox_username.Text.Trim & "','" & txtbox_password.Text & "','" & txtbox_add.Text & "','" & txtbox_contact.Text & "','" & today.ToString & "','" & answer.ToString & "',1)", Connection)
command1.ExecuteNonQuery()
MsgBox("Profile Successfuly Saved")
Dim command2 As New MySqlCommand("Select * From userscanner WHERE Username = '" & txtbox_username.Text & "' ", Connection)
command2.ExecuteNonQuery()
Dim dr1 As MySqlDataReader
dr1 = command2.ExecuteReader
dr1.Read()
Dim id As Integer = .Item(0)
Dim Username As String = .Item(1)
Dim command3 As New MySqlCommand("Insert into Trasnsaction (ID,Username,Description,Date) VALUES('" & id & "','" & Username & "','Register Account','" & today & "')", Connection)
command3.ExecuteNonQuery()
dr1.Close()
Me.Close()
frm_main.Show()
让我们关注这些行:
Dim command2 As New MySqlCommand("Select * From userscanner WHERE Username = '" & txtbox_username.Text & "' ", Connection)
command2.ExecuteNonQuery()
Dim dr1 As MySqlDataReader
dr1 = command2.ExecuteReader
上面的代码产生一个错误说明:
datareader中没有当前查询。
问题出在哪里,我该如何解决?
最佳答案
您可能在这里缺少With
语句,例如With dr1
行之后的dr1.Read()
...但是我只是这样更改它:Dim id as Integer = dr1(0)
Dim Username As String = dr1(1)