none
I get "Invalid attempt to read when no data is present." while trying to read data RRS feed

  • Question

  • Hey There ,
    I to Got Same Error But i am Trying to Get the Values Stored In tables with DATA READER and Check them witth the Label ID And other Filed I want it is working fine in ADO but not with READER i Dont Understand i Tried a Lot Of Thing but in Vain can any one Suggest me a sloution pls...
    Here Is my Code


     Protected Sub DropDownList1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged
          
            Dim a As String
            Dim b As String
            Dim c As String
            Dim d As String
            b = ""
            a = ddl1.SelectedIndex
            If a = "0" Then
                b = "optlang2"
            Else
                b = "lang1"
            End If

            Dim connString As String = "Server=localhost;Database=Analyzer;User Id= sa;Password=redcat005;Integrated Security=SSPI"
            Dim sql As String = "SELECT id," & b & " FROM lang"

            Dim conn As SqlConnection = New SqlConnection(connString)
            Dim command As SqlCommand = New SqlCommand(sql, conn)
            conn.Open()
            Dim Rs As SqlDataReader = command.ExecuteReader()
            Me.DataList1.DataSource = Rs
            Me.DataList1.DataBind()
            'MsgBox(Rs.Item(0).ToString)
            Rs.Read()
            Do While Rs.HasRows = True
                c = Rs.GetSqlValue(0)
                d = Rs.GetSqlValue(1)
                'Label() 's
                If Me.sChPi_lbl0.ID = c Then
                    Me.sChPi_lbl0.Text = d
                End If
                If Me.sChPi_lbl1.ID = c Then
                    Me.sChPi_lbl1.Text = d
                End If
                If Me.sChPi_lbl2.ID = c Then
                    Me.sChPi_lbl2.Text = d
                End If
                If Me.sChPi_lbl3.ID = c Then
                    Me.sChPi_lbl3.Text = d
                End If
                If Me.sChPi_btn1.ID = c Then
                    Me.sChPi_btn1.Text = d
                End If
                Rs.NextResult()
            Loop
        End Sub


    its a funtion which does all thing i need to call it on DropDownList SelectedIndex Value Changed Please Help....
    Tuesday, April 8, 2008 9:30 AM

Answers

  • When you call ExecuteMethod of reader, resultset will be closed and it does not start actual reading until you call Read method. You also use return boolean value of Read method it see if you reader got any result back from the data source, like

     

    Dim Rs As SqlDataReader = command.ExecuteReader()
    If  Rs.Read() Then

    .... Do something here

     

    End IF

     

    Tuesday, April 8, 2008 10:13 AM
    Moderator

All replies

  • When you call ExecuteMethod of reader, resultset will be closed and it does not start actual reading until you call Read method. You also use return boolean value of Read method it see if you reader got any result back from the data source, like

     

    Dim Rs As SqlDataReader = command.ExecuteReader()
    If  Rs.Read() Then

    .... Do something here

     

    End IF

     

    Tuesday, April 8, 2008 10:13 AM
    Moderator
  • Thanx a Lot Buddy
    It actully Worked .. One Thing i Noticed Was Even Though The Loop And Reader Go Excuted it Did not show me more than one record.. where as i have more than one row(s) to be affected






    Tuesday, April 8, 2008 11:24 AM


  • I want to change height and width for a webpart when i move one webpart from one to another zone.

     i have two zone. My first zone have small width and hieght 100px X 75px  and second zone has large width and height 650px X 250Px.

    i have 10 webpart in my first zone.

    and i want show webpart with 650Px X 250Px as i move webpart in second zone from first zone. i try to write some code for the same.
    for your ref Here is The Code.

     'Report Viewer 1
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer1.ShowToolBar = True
                Me.ReportViewer1.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer1.Width = WebPartZone2.Width
            Else
                Me.ReportViewer1.ShowToolBar = False
                Me.ReportViewer1.Height = 75
                Me.ReportViewer1.Width = WebPartZone1.Width
                Me.ReportViewer1.ZoomPercent = 30
            End If

            'Report Viewer 2
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer2.ShowToolBar = True
                Me.ReportViewer2.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer2.Width = WebPartZone2.Width
            Else
                Me.ReportViewer2.ShowToolBar = False
                Me.ReportViewer2.Height = 75
                Me.ReportViewer2.Width = WebPartZone1.Width
                Me.ReportViewer2.ZoomPercent = 30
            End If

            'Report Viewer 3
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer3.ShowToolBar = True
                Me.ReportViewer3.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer3.Width = WebPartZone2.Width
            Else
                Me.ReportViewer3.ShowToolBar = False
                Me.ReportViewer3.Height = 75
                Me.ReportViewer3.Width = WebPartZone1.Width
                Me.ReportViewer3.ZoomPercent = 30
            End If

            'Report Viewer 4
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer4.ShowToolBar = True
                Me.ReportViewer4.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer4.Width = WebPartZone2.Width
            Else
                Me.ReportViewer4.ShowToolBar = False
                Me.ReportViewer4.Height = 75
                Me.ReportViewer4.Width = WebPartZone1.Width
                Me.ReportViewer4.ZoomPercent = 30
            End If

            'Report Viewer 5
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer5.ShowToolBar = True
                Me.ReportViewer5.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer5.Width = WebPartZone2.Width
            Else
                Me.ReportViewer5.ShowToolBar = False
                Me.ReportViewer5.Height = 75
                Me.ReportViewer5.Width = WebPartZone1.Width
                Me.ReportViewer5.ZoomPercent = 30
            End If

            'Report Viewer 6
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer6.ShowToolBar = True
                Me.ReportViewer6.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer6.Width = WebPartZone2.Width
            Else
                Me.ReportViewer6.ShowToolBar = False
                Me.ReportViewer6.Height = 75
                Me.ReportViewer6.Width = WebPartZone1.Width
                Me.ReportViewer6.ZoomPercent = 30
            End If

            'Report Viewer 7
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer7.ShowToolBar = True
                Me.ReportViewer7.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer7.Width = WebPartZone2.Width
            Else
                Me.ReportViewer7.ShowToolBar = False
                Me.ReportViewer7.Height = 75
                Me.ReportViewer7.Width = WebPartZone1.Width
                Me.ReportViewer7.ZoomPercent = 30
            End If

            'Report Viewer 8
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer8.ShowToolBar = True
                Me.ReportViewer8.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer8.Width = WebPartZone2.Width
            Else
                Me.ReportViewer8.ShowToolBar = False
                Me.ReportViewer8.Height = 75
                Me.ReportViewer8.Width = WebPartZone1.Width
                Me.ReportViewer8.ZoomPercent = 30
            End If

            'Report Viewer 9
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer9.ShowToolBar = True
                Me.ReportViewer9.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer9.Width = WebPartZone2.Width
            Else
                Me.ReportViewer9.ShowToolBar = False
                Me.ReportViewer9.Height = 75
                Me.ReportViewer9.Width = WebPartZone1.Width
                Me.ReportViewer9.ZoomPercent = 30
            End If

            'Report Viewer 10
            If e.Zone.DisplayTitle = "Enlarge Mode" Then
                e.WebPart.Height = WebPartZone2.Height
                e.WebPart.Width = WebPartZone2.Width
                Me.ReportViewer10.ShowToolBar = True
                Me.ReportViewer10.ZoomMode = Microsoft.Reporting.WebForms.ZoomMode.PageWidth
                Me.ReportViewer10.Width = WebPartZone2.Width
            Else
                Me.ReportViewer10.ShowToolBar = False
                Me.ReportViewer10.Height = 75
                Me.ReportViewer10.Width = WebPartZone1.Width
                Me.ReportViewer10.ZoomPercent = 30
            End If
    Tuesday, April 8, 2008 11:33 AM