请考虑以下代码:
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中没有当前查询。
问题出在哪里?我该如何解决?
答案 0 :(得分:0)
您可能在With
行之后错过了With dr1
语句,例如dr1.Read()
行之后的Dim id as Integer = dr1(0)
...但我会改变它:
Dim Username As String = dr1(1)
{{1}}