JennyD6856 says:
for
(
int
i = 0; i < dsCustomers.Tables[0].Rows.Count; i++)
{
string
path = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10)) +
"\\Reports\\RecieptReport.rpt"
;
report1.Load(path);
DateTime dateTime = Convert.ToDateTime(dsCustomers.Tables[0].Rows[i][
"ContractStartdate"
]);
string
ContractStartdate = dateTime.ToString(
"dd/MM/yyyy"
);
report1.SetParameterValue(
"TodayDate"
, System.DateTime.Now.Date.ToString(
"dd/MM/yyyy"
));
report1.SetParameterValue(
"DepositeAmount"
, dsCustomers.Tables[0].Rows[i][
"DepositeAmount"
].ToString());
report1.SetParameterValue(
"ReceiptNo"
, dsCustomers.Tables[0].Rows[i][
"CustomerId"
].ToString());
report1.SetParameterValue(
"CustomerName"
, dsCustomers.Tables[0].Rows[i][
"CustomerNameArabic"
].ToString());
report1.SetParameterValue(
"AmountInWord"
, dsCustomers.Tables[0].Rows[i][
"AmountInWord"
].ToString());
report1.SetParameterValue(
"ContactStartdate"
, ContractStartdate);
report1.SetParameterValue(
"BuildingCode"
, dsCustomers.Tables[0].Rows[i][
"BuildingCode"
].ToString());
report1.SetParameterValue(
"FlatNo"
, dsCustomers.Tables[0].Rows[i][
"FlatNo"
].ToString());
crystalReportViewer1.ReportSource = report1;
}
For displaying multiple you don't need to use foor loop.
You need to set the DataSource to the ReportDocument and reportDocument to the ReportSource property of CrystalReportViewer.
Using below article i have created the example.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Report Design
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
ReportDocument reportDocument = new ReportDocument();
Customers dsCustomers = GetData();
if (dsCustomers.Tables[0].Rows.Count > 0)
{
string path = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10)) + "\\CustomerReport.rpt";
reportDocument.Load(path);
reportDocument.SetDataSource(dsCustomers);
crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.RefreshReport();
}
}
private Customers GetData()
{
string constr = @"Data Source=.;Initial Catalog=Northwind;UID=sa;PWD=pass@123;";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 5 * FROM Customers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
}
VB.Net
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim reportDocument As ReportDocument = New ReportDocument()
Dim dsCustomers As Customers = GetData()
If dsCustomers.Tables(0).Rows.Count > 0 Then
Dim path As String = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10)) & "\CustomerReport.rpt"
reportDocument.Load(path)
reportDocument.SetDataSource(dsCustomers)
CrystalReportViewer1.ReportSource = reportDocument
CrystalReportViewer1.RefreshReport()
End If
End Sub
Private Function GetData() As Customers
Dim constr As String = "Data Source=.;Initial Catalog=Northwind;UID=sa;PWD=pass@123;"
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT TOP 5 * FROM Customers")
Using sda As SqlDataAdapter = New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dsCustomers As Customers = New Customers()
sda.Fill(dsCustomers, "DataTable1")
Return dsCustomers
End Using
End Using
End Using
End Using
End Function
Screenshot