Hi PRA,
I have created sample that full-fill your requirement. Refer the below article for creating crystal report using stored procedure.
SQL
CREATE PROCEDURE GetPersonInformation
@SearchTerm VARCHAR(50) = NULL
AS
BEGIN
SELECT pt.ID,it.Information,CONVERT(VARCHAR,it.DateInputInfo,104) DateInputInfo
FROM PersonTable pt
INNER JOIN InfoTable it ON it.PersonId = pt.ID
WHERE pt.LastName LIKE '%'+@SearchTerm+'%'
OR @SearchTerm IS NULL
END
HTML
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSearchTerm" runat="server" Text="Search" OnClick="SearchClick" />
<br />
<CR:CrystalReportViewer ID="crPersonInformation" runat="server" AutoDataBind="true" />
</div>
Code
protected void SearchClick(object sender, EventArgs e)
{
string searchTerm = txtSearch.Text.Trim();
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/PersonInformationReport.rpt"));
PersonInformation dsPersonInformations = GetPersonInformations(searchTerm);
crystalReport.SetDataSource(dsPersonInformations);
crPersonInformation.ReportSource = crystalReport;
}
private PersonInformation GetPersonInformations(string searchTerm)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand("GetPersonInformation");
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchTerm", searchTerm);
sda.SelectCommand = cmd;
using (PersonInformation dsPersonInformations = new PersonInformation())
{
sda.Fill(dsPersonInformations, "PersonInformation");
return dsPersonInformations;
}
}
}
}
Screenshot