Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using crystal reports as follows.i m passing three parameters fromdate,todate and userid to my query for loading crystal report.the crystal report loads properly and the query also brings the records properly.I m binding report from code behind as follows.

on page load and GenerateReport button click :-
ReportDocument rptDoc = new ReportDocument();
dsSample ds = new dsSample(); //.xsd file name
DataTable dt = new DataTable();

// Just set the name of data table
dt.TableName = "Crystal Report";
dt = getAllData(); //This function is located below this function
ds.Tables[0].Merge(dt);

// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("CReport2.rpt"));

//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();

Getalldata function contains the query as

private DataTable getAllData()
{
//int Uid = Convert.ToInt32(ddlUser.SelectedValue);
//txtFrom.Text =
//txtTo.Text = Session["FrmDateRpt"].ToString();//currentdate can also be used
//ddlUser.SelectedValue = Session["UsrRpt"].ToString();


DataSet ds = null;
try
{
// Open Sql Connection
string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
SqlConnection SqlCon = new SqlConnection(connstr);
SqlCon.Open();

// Create a Command
SqlCommand SqlComm = new SqlCommand();
SqlComm.Connection = SqlCon;
SqlComm.CommandType = CommandType.Text;

string query = "SELECT first_name,last_name,country,Quantity FROM Table1 where convert(datetime,FromDate,101) >='" + txtFrom.Text + "' and convert(datetime,ToDate,101) <='" + txtTo.Text + "' and userid =" + ddlUser.SelectedValue + "" ;


SqlComm.CommandText = query;

ds = new DataSet();
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlComm);
SqlDa.Fill(ds, "DataTable1");


}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{

}
return ds.Tables[0];
}
Report shows me some records on first page but when i click on next page button to see more records it dispalys no records.Whats the problem i m not able to understand.Help Me..
Posted
Comments
thatraja 3-Feb-14 2:13am    
Where did you write this code? which event?
pwavell 3-Feb-14 2:14am    
page load and button click

1 solution

Move your code to Page_Init event
How to navigate page in crystal report using toolbar?[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900