gpt4 book ai didi

mysql - 如何解决 "No query in datareader"错误?

转载 作者:行者123 更新时间:2023-11-29 22:35:24 25 4
gpt4 key购买 nike

考虑以下代码:

 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

上面的代码产生一个错误,指出:

No current query in datareader.

问题出在哪里以及如何解决?

最佳答案

您可能在这里缺少 With 语句,例如 dr1.Read() 行后面的 With dr1...但我只需像这样更改它:

将 id 调暗为 Integer = dr1(0)
将用户名变暗为字符串 = dr1(1)

关于mysql - 如何解决 "No query in datareader"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29566559/

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