Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Hi

I'm new in Webform with Crystal Report in visual studio 2012 and framework 4.5. I able to build a Crystal report in web form. But it not displaying any thing. Here I will describe what I did.



1. Download "CRforVS_13_0_5.exe" and installed.

2. create dataset (dbDemo.xsd)

3. Create a .rpt file(CRReport.rpt) in my ASP.NET project. and Set the database field

4. Below is my code to display the report

C#CODE

C#
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;





protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dbDemo ds = new dbDemo(); // .xsd file name
DataTable dt = new DataTable();

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

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

//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
rptDoc.SetDatabaseLogon("tps_ideal", "idealpw");
CrystalReportViewer1.ReportSource = rptDoc;

CrystalReportViewer1.DisplayToolbar = true;




}
public DataTable getorder()
{//Connection string replace 'databaseservername' with your db server name
SqlConnection MyConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
//SqlConnection Con = new SqlConnection(MyConn);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
MyConn.Open();
//Stored procedure calling. It is already in sample db.
cmd.CommandText = "BindReportView";
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@DOCID", "Doc/001");
cmd.Parameters.AddWithValue("@DOCNAME", "Test Roshni Doc/001");
cmd.Connection = MyConn;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Users");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (MyConn.State != ConnectionState.Closed)
MyConn.Close();
}
return ds.Tables[0];
}





HTML CODE

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="Sample.Demo" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html>

<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>



I don't know for viewing we need anything additional. When I debugging, I'm getting the value in my dataset "testds"
Posted
Updated 4-Aug-14 3:42am

1 solution

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