1
누구든지 내 코드에 문제가 있다고 말할 수 있습니까? 나는 vb.net에서 새로운 개발 코드이므로 일부 참조 코드를 온라인으로 가지고있다. &이 코드를 작성하려고했지만 오류가 발생했다. & 내가 잘못하고있는 곳을 알려주십시오. 제 코드를 수정하십시오.이 연결과 관련된 DataReader는 먼저 닫아야합니다.
오류 먼저이 연결과 연결된 열려있는 DataReader가 있으며 먼저 닫아야합니다.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not String.IsNullOrEmpty(lblId.Text) Then
Dim query As String = "Select ID, email From users where [email protected]"
con.Open()
Dim cmd As New MySqlCommand(query, con)
cmd.Parameters.AddWithValue("@id", lblId.Text)
Dim dr As MySqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
'Do Login Code here
Try
Dim str As String = "select * from users where ID='" + lblId.Text + "';"
Dim cmd2 As New MySqlCommand(str, con)
Dim da As New MySqlDataAdapter(cmd2)
Response.Cookies("User_Type").Value = "users"
Response.Cookies("chkusername").Value = lblId.Text
Response.Redirect(Request.Url.AbsoluteUri)
Catch ex As Exception
Response.Write(ex)
End Try
Else
Try
Dim str1 As String = "INSERT INTO users (ID, DP, displayName) values('" + lblId.Text + "', '" + ProfileImage.ImageUrl.ToString + "', '" + lblName.Text + "')"
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = str1
command.Connection = con
adapter.SelectCommand = command
command.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex)
End Try
End If
End If
con.Close()
End Sub
두 개의 중첩 된 명령에 대해 동일한 연결을 사용하고 있습니다. 내가 알고있는 한, 두 개의 별도 연결이 필요합니다. – Steve
동일한 연결 내에서 다른 SQL 명령 ('select * from users, INSERT INTO users ... ')을 실행하기 전에 DataReader를 닫아야합니다. –
@ 스티브 정류장 답변을 게시 할 수 있습니다 – SUN