我在編碼中得到這個錯誤,請告訴我什麼可能是錯誤的?以及如何糾正它在我的if語句中的其他部分我有這個錯誤,請告訴我如何解決它
已經有一個與此連接關聯的打開的DataReader,必須先關閉它。 這裏在這個子部分,我檢索數據中的if部分和我插入數據的其他部分。如果條件不滿意。所以在其他部分我收到上述錯誤
代碼:
Dim con As MySql.Data.MySqlClient.MySqlConnection = New MySqlClient.MySqlConnection("server=localhost;user=root;database=zzz;port=3306;password;")
con.Open()
Dim cmd As MySqlClient.MySqlCommand
Dim dr As MySqlClient.MySqlDataReader
cmd = con.CreateCommand()
cmd.CommandText = "select sino FROM customers WHERE sino =('" + serialno.Text + "')"
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader()
If dr.HasRows = True Then
MsgBox("number already exists")
dr.Close()
ElseIf dr.HasRows = False Then
Dim sqlc As String
sqlc = "insert into customers values('" + serialno.Text + "','" + custname.Text + "','" + address.Text + "','" + phno.Text + "','" + eid.Text + "','" + event_type.Text + " ')"
Dim command As MySqlClient.MySqlCommand = New MySqlClient.MySqlCommand(sqlc, con)
command.ExecuteNonQuery()
MessageBox.Show(sqlc)
con.Close()
End If
我認爲一個簡單的谷歌搜索將你解決問題了http://stackoverflow.com/questions/5440168/c-sharp-mysql-there-is-already-an-open- datareader-associated-with-this-connectio – spullen 2013-03-22 15:06:54
請問你可以粘貼一些代碼.. – 2013-03-22 15:07:18
我推薦,在解決DataReader的問題之後,立即研究Sql Injection問題。你的查詢有一個巨大的安全漏洞。 – Steve 2013-03-22 15:19:54