This is a migrated thread and some comments may be shown as answers.

Using ado.net's ExecuteReader in ado.net throws error " Invalid attempt to read when no data is present." -- ???

1 Answer 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 09 May 2013, 06:59 PM
I am sure I must be missing something simple here, but I can't seem to user an ado.net datareader with reporting. Here is a code sample:

Private Sub RptRadIdleTime_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
        rptHeaderBox.Value = "Report Criteria:" & vbCrLf & "Date Range: " & StartDate.ToShortDateString & " to " & EndDate.ToShortDateString & vbCrLf & _
        "Employee: " & EmployeeName & vbCrLf
 
        Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
 
        cn.Open()
 
        Dim cmd As New SqlCommand("ReportIdleTime")
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = cn
        cmd.Parameters.Add(New SqlParameter("EmployeeID", EmployeeID))
 
        Dim p1 As New SqlParameter("Start", SqlDbType.DateTime)
        p1.Value = CDate(StartDate)
 
        Dim p2 As New SqlParameter("End", SqlDbType.DateTime)
        p2.Value = CDate(EndDate)
 
        cmd.Parameters.Add(p1)
        cmd.Parameters.Add(p2)
        Me.DataSource = cmd.ExecuteReader
    End Sub

This yields the following error:

An error has occurred while processing TextBox 'TextBox6': Invalid attempt to read when no data is present.

(And the same error on every other field.)

The same method of connecting works fine with linq-to-sql.

Thanks for any help,

David

1 Answer, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 14 May 2013, 03:59 PM
Hello,

We have reproduced the exception and will take the necessary steps to fix the problem. Meanwhile our suggestion is to use SqlDataSource component instead of a SqlCommand or an ObjectDataSource component with a business object which wraps the reader as shown in the help article.

Regards,
Chavdar
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Chavdar
Telerik team
Share this question
or