Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

Problem in Printing and Reporting Crystal Report

$
0
0

I'm Using VS2010 and SQL Server.

The below code is I have used in my page for Crystal report.

//Here I retrieve User Name from another page using session

protected void Page_Load(object sender, EventArgs e)
{
lblUserName.Text = Session["empName"].ToString();
}


protected void btnRpt_Click(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
DSsample ds = new DSsample(); // .xsd file name
DataTable dt = new DataTable();
dt.TableName = "Crstal Report";
dt = GetAllOrders();
ds.Tables[0].Merge(dt);
if (ds.Tables[0].Rows.Count > 0)
{
rptDoc.Load(Server.MapPath("~/CrystalReport.rpt"));

rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
}
else
{
Response.Write("<script type=\"text/javascript\">alert('No record found for the month & year!...');</script>");
}
}


public DataTable GetAllOrders()
{
SqlConnection cn = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=salaryReg;User ID=sa;Password=kavi");
SqlCommand cmd = new SqlCommand("Select * from SalaryEarnings where empName='" + lblUserName.Text + "' and Salary_Year='" + ddlYear.Text + "' and Salary_Month='" + ddlMonth.Text + "'", cn);
DataSet ds = null;
SqlDataAdapter da;
try
{
cn.Open();
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds, "User");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (cn.State != ConnectionState.Closed)
cn.Close();
}
return ds.Tables[0];
}

this is the code I've used to generate crystal report in one of my asp.net web site under button click event. This create report without any errors but after that when i click print button on crystal report tool bar print function is not working and when try to do Exporting the report it asks for further details by giving a window like this

The report you requested requires further information.
DataSet
Server name: ...........
Database name: .........
User name: ..........
Password: ........... 
(checkbox) Use Integrated Security.

Please Tell me What I need to do Printing and Exporting my records.


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>