ReportViewer and C#

B

BadStorm

Hi,
I have an application that on runtime generate a datatable with a list of
persone, with name, andress, etc..
I want to add the posbility to print the list of all the person, and I want
to use ReportViewer. But I have this problem:
I create with the designer my report, without set and datasource. Then from
code:

SqlDataAdapter Read = new SqlDataAdapter("SELECT * FROM People",
Connection);
DataTable PeopleTable = new DataTable();
Read.Fill(PeopleTable);
reportViewer1.LocalReport.DataSources.Add(new
Microsoft.Reporting.WinForms.ReportDataSource("People", PeopleTable));
reportViewer1.LocalReport.ReportEmbeddedResource =
"MyReports.Report1.rdlc";

But when I test my program I get this error:

The Value expression for the textbox 'textbox1' refers to
the field 'Name'. Report item expressions can only refer to fields within
the current data set scope or, if inside an aggregate, the specified
data set scope.

My question is: It is possible to use a Report.rdcl create with the
designer, with a runtime dataset?
In a textbox of the Report.rdcl wath value is to set? Now I used
=Fields!Name.Value

Thanks

Marco
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,
I have an application that on runtime generate a datatable with a list of
persone, with name, andress,  etc..
I want to add the posbility to print the list of all the person, and I want
to use ReportViewer. But I have this problem:
I create with the designer my report, without set and datasource. Then from
code:

            SqlDataAdapter Read = new SqlDataAdapter("SELECT * FROM People",
Connection);
            DataTable PeopleTable = new DataTable();
            Read.Fill(PeopleTable);
            reportViewer1.LocalReport.DataSources.Add(new
Microsoft.Reporting.WinForms.ReportDataSource("People", PeopleTable));
            reportViewer1.LocalReport.ReportEmbeddedResource =
"MyReports.Report1.rdlc";

But when I test my program I get this error:

                The Value expression for the textbox 'textbox1' refers to
the field 'Name'.  Report item expressions can only refer to fields within
the current data set scope or, if inside an aggregate, the specified
                data set scope.

My question is: It is possible to use a Report.rdcl create with the
designer, with a runtime dataset?
In a textbox of the Report.rdcl wath value is to set? Now I used
=Fields!Name.Value

Thanks

Marco

Is it the same for you using Crystal Reports?
If so, create a sample dataset of the struct you want to use, save it
to disk using DataSet.WriteXml( ... , XmlWriteMode.WriteSchema)
then create your project and set the datasource to the above created
file.
at runtime you set fill your dataset as you find fit and then just
call ReportDocument.SetDataSource( myDataset);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top