2获取数据执行时出现Gridview错误reader错误 [英] 2 Gridview error on getting data executereader error

查看:51
本文介绍了2获取数据执行时出现Gridview错误reader错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,第一个我说错了"There is already an open DataReader associated with this Command which must be closed first"
所以我更改了代码,我关闭了第一个阅读器,所以现在是我的代码了

Hello Guys, first ive got an error saying"There is already an open DataReader associated with this Command which must be closed first"
So I change my code I close the first reader soo here is my code now

If (IsPostBack = False) Then
            Dim strSQL As String
            Dim strSQL2 As String
            Dim SQLreader As SqlClient.SqlDataReader
            Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
            strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan]WHERE ([Category] = @Category)"

            connection.Open()
            Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
            myCommand.Parameters.AddWithValue("@Category", lblGEE.Text)
            SQLreader = myCommand.ExecuteReader()
            SQLreader = GridView1.DataSource
            GridView1.DataBind()
            SQLreader.Close()
            strSQL2 = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan]WHERE ([Category] = @Category)"
            Dim myCommand2 As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL2, connection)
            myCommand2.Parameters.AddWithValue("@Category", lblCross.Text)
            TPCross.DataSource = myCommand2.ExecuteReader()
            TPCross.DataBind()
            connection.Close()
            connection.Close()

        End If



我的问题是当我运行它时,出现新错误,提示Object reference not set to an instance of an object.
请帮助我,我不知道香港专业教育学院错了.
在此先感谢您和更多程序的帮助^ _ ^



My problem is when i run it new error occured sayingObject reference not set to an instance of an object.
Help plss I dont know where ive got wrong.. Keep banging my head just to solved this problem.

Thanks in advance and more programming to come ^_^

推荐答案

发现了错误. Microsoft不支持多个读取器,因此我关闭了所有连接并创建了另一个连接器. sk! Microsoft ^ _ ^,让我发疯!!
found the error. The Microsoft doest support multiple readers so i close all the connections and create another. Tsk! Microsoft ^_^, makes my head crazy!!


使用DataTable代替SqlDataReader. DataTable支持您的需求.
Use DataTable instead of the SqlDataReader. DataTable supports your need.


这篇关于2获取数据执行时出现Gridview错误reader错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆