Hai, I'm using VS2010.
I have a problem in Crystal Report. I want to all records from database table and Display in Crystal Report.
I'm using the following coding for above that purpose, But it display only first row of the table. See my code,
Report.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" />
</div>
</form>
</body>
</html>
Report.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
txtID.Text = Session["ID"].ToString();
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/stdCR.rpt"));
std ds = GetData("select * from empdet");
crystalReport.SetDataSource(ds);
CrystalReportViewer1.ReportSource = crystalReport;
}
private std GetData(string query)
{
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=example;User ID=sa;Password=kavi"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (std ds = new std())
{
sda.Fill(ds, "DataTable1");
return ds;
}
}
}
}