Skip to Content
author's profile photo Former Member
Former Member

How to Bind .NET Objects as DataSource to a Report? (DataSourceException)


I'm already trying for hours and I still can't produce a Report from scratch with a .NET Object.

Everytime I call the SetDataSource-Method, I Get the DataSourceException:

I'm using Visual Studio 2013 Update 5 with CRforVS_13_0_13

Failed to load database information.

Error in File temp_54f4ace5-3d4b-49f4-a633-cb7098cbf8bd 10164_1776_{D1ADA617-8049-497D-BD87-2530EA8EEE81}.rpt:


at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)

at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type)

at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet)

at WindowsApplication12.Form1.Button1_Click(Object sender, EventArgs e) in c:\users\danielr\documents\visual studio 2013\Projects\WindowsApplication12\WindowsApplication12\Form1.vb:line 18

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

What I'm doing:

I have a simple WinForms Application in which is just a Button. In the Click-Event I Initialize the Report, a List(Of TestClass) and a DataSet out of the List. Then I'm setting the DataSource and the Exceptionis thrown. For the Report I made a XSD File out of the List first, then generated the Report and set the XSD as DataSourceConnection for the Report.

Here is the SourceCode:

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim testData = GenerateTestData()

Dim dataSet = ListToDataSet(testData)

Dim report = New CrystalReport1()

''Make a XSD File out of the DataSet for the Report (this step is just made initially)

'Dim writer = New IO.StreamWriter("Test.xsd")



''Set the DataSource for the Report


''Export it to a PDF and then open it

report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "test.pdf")


''Exit the Application


End Sub

''' <summary>

''' Generates some TestData

''' </summary>

''' <returns></returns>

''' <remarks></remarks>

Public Function GenerateTestData() As List(Of TestClass)

Dim r = New Random()

Dim list = New List(Of TestClass)

For i As Integer = 0 To 100

list.Add(New TestClass() With {.Betrag = r.Next(),

.Name = "TestName" & i})


Return list

End Function

''' <summary>

''' Makes a DataSet

''' </summary>

''' <typeparam name="T"></typeparam>

''' <param name="dataList"></param>

''' <returns></returns>

''' <remarks></remarks>

Public Function ListToDataSet(Of T)(dataList As IEnumerable(Of T)) As DataSet

Dim dataTable = New DataTable(GetType(T).Name)

Dim propInfos() As PropertyInfo = Nothing

For Each rec As T In dataList

If propInfos Is Nothing Then

propInfos = rec.GetType().GetProperties()

For Each propInfo In propInfos

Dim columnType = propInfo.PropertyType

If columnType.IsGenericType AndAlso columnType.GetGenericTypeDefinition = GetType(Nullable(Of )) Then

columnType = columnType.GetGenericArguments(0)

End If

dataTable.Columns.Add(New DataColumn(propInfo.Name, columnType))


End If

Dim dataRow As DataRow = dataTable.NewRow()

For Each propInfo In propInfos

dataRow(propInfo.Name) = If(propInfo.GetValue(rec, Nothing), DBNull.Value)




Dim dataSet = New DataSet()


Return dataSet

End Function

End Class

The Test Class is quite simple:

Public Class TestClass

Property Name As String

Property Betrag As Integer

End Class

The Report is just made out of the Standard Dialogue (New Item => Crystal Report => OK => Selected the TestClass DataSet => Next and so on) and looks like this

Could someone please help me?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Aug 18, 2015 at 09:57 PM

    See if this KBA will help.

    Oh. And update to SP 14 (use the install exe). SP 13 was a bit weak.

    - Ludek

    Senior Support Engineer AGS Product Support, Global Support Center Canada

    Follow me on Twitter

    Message was edited by: Ludek Uher

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.