โดยที่ GridView1 ดึงข้อมูลจากตาราง A
และ GridView2 ดึงข้อมูลจากตาราง B
มันขึ้น Error :There is already an open DataReader associated with this Command which must be closed first.
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Partial Class Index
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("login") = "" Then
Me.Response.Redirect("default.aspx")
End If
Dim strConn As String
Dim myConn As SqlConnection
strConn = "Data Source=xxxxx; Initial Catalog=xxxx; User Id=sa; Password=xxxxxx;"
myConn = New SqlConnection(strConn)
myConn.Open()
'GridView1
Dim DATAReader As SqlDataReader
Dim Cmd As SqlCommand = New SqlCommand("SELECT xxx FROM A", myConn)
DATAReader = Cmd.ExecuteReader()
GridView1.DataSource = DATAReader
GridView1.DataBind()
'GridView2
Dim DATAReader2 As SqlDataReader
Dim Cmd2 As SqlCommand = New SqlCommand("SELECT xxx FROM B", myConn)
DATAReader2 = Cmd2.ExecuteReader()
GridView2.DataSource = DATAReader2
GridView2.DataBind()
End Sub
End Class
ต้องแก้ไขยังไงครับ
Tag : .NET, Ms SQL Server 2005, VBScript, Web (ASP.NET), VB.NET, VS 2005 (.NET 2.x)