I am printing reports using Report Viewer. I followed a tutorial about this code but I got this error "Cannot create a data reader for dataset 'Dataset1'.
I am using reportviewer and rdlc in this. I dont know if the problem is the the Reportdatasource itself or the dataset:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using MySql.Data.MySqlClient;
namespace Water_Quality_Monitoring
{
public partial class FishpondForm : Form
{
Microsoft.Reporting.WinForms.ReportDataSource rs = new
Microsoft.Reporting.WinForms.ReportDataSource();
private DataGridView grid;
public FishpondForm()
{
InitializeComponent();
}
private void btnPrint_Click(object sender, EventArgs e)
{
List<Print> list = new List<Print>();
list.Clear();
for (int i = 0; i < agriInfo.dataAgriInfo.Rows.Count - 1; i++)
{
list.Add(new Print
{
MemberID =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString(),
LastName =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString(),
FirstName =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString(),
MiddleName =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString(),
Contact =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString(),
Status =
agriInfo.dataAgriInfo.Rows[i].Cells[0].Value.ToString()
});
Microsoft.Reporting.WinForms.ReportDataSource rs = new
Microsoft.Reporting.WinForms.ReportDataSource();
rs.Name = "Dataset1";
rs.Value = list;
PrintFishpond frm = new PrintFishpond();
frm.reportViewer1.LocalReport.DataSources.Clear();
frm.reportViewer1.LocalReport.DataSources.Add(rs);
frm.reportViewer1.LocalReport.ReportEmbeddedResource =
"Water_Quality_Monitoring.Report1.rdlc";
frm.ShowDialog();
}
}
}
public class Print
{
public string MemberID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string Contact { get; set; }
public string Status { get; set; }
}
}
I expect to print what is in the datagrid dataAgriInfo. I hope you can help me.