Hi jmprateek
Note:I have created sample by refering the below Article. For more details pleaser refer below Article.
HTML
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/Sales.rpt"));
DataSet1 dsCustomers = GetData("SELECT bno,name,cdate,totalgst,disc,paidamt,pymtmode from Sales where convert(varchar(50),cdate,105) >= convert(varchar(50),'03-10-2021',103) AND convert(varchar(50),cdate,105) < convert(varchar(50),'07-01-2022',103) and bno!='0' group by bno,name,cdate,totalgst,disc,paidamt,pymtmode");
crystalReport.SetDataSource(dsCustomers);
CrystalReportViewer1.ReportSource = crystalReport;
}
public DataSet1 GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
cmd.Connection = con;
using (DataSet1 dsCustomers = new DataSet1())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim crystalReport As ReportDocument = New ReportDocument()
crystalReport.Load(Server.MapPath("~/Sales.rpt"))
Dim dsCustomers As DataSet1 = GetData("SELECT bno,name,cdate,totalgst,disc,paidamt,pymtmode from Sales where convert(varchar(50),cdate,105) >= convert(varchar(50),'03-10-2021',103) AND convert(varchar(50),cdate,105) < convert(varchar(50),'07-01-2022',103) and bno!='0' group by bno,name,cdate,totalgst,disc,paidamt,pymtmode")
crystalReport.SetDataSource(dsCustomers)
CrystalReportViewer1.ReportSource = crystalReport
End Sub
Public Function GetData(ByVal query As String) As DataSet1
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim cmd As SqlCommand = New SqlCommand(query)
Using con As SqlConnection = New SqlConnection(conString)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
cmd.Connection = con
Using dsCustomers As DataSet1 = New DataSet1()
sda.Fill(dsCustomers, "DataTable1")
Return dsCustomers
End Using
End Using
End Using
End Function
Screenshot