如何解决“在数据读取器中没有查询"?错误? [英] How to solve "No query in datareader" error?
本文介绍了如何解决“在数据读取器中没有查询"?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
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
上面的代码产生一个错误,指出:
The above code produces an error stating :
数据读取器中没有当前查询.
No current query in datareader.
问题出在哪里,我该如何解决?
Where is the problem and how can I fix it?
推荐答案
您可能在这里缺少With
语句,例如With dr1
紧接在dr1.Read()
行之后...但是我只是这样更改它:
You might be missing a With
statement here, like With dr1
right after the dr1.Read()
line...but I would just change it like this:
Dim id as Integer = dr1(0)
Dim Username As String = dr1(1)
这篇关于如何解决“在数据读取器中没有查询"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文