Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i use asp.net, c++, crystal report for my report and sql database with windows authentication login.

been looking in the internet for the answer but it seems i can not find. i really hopping to solve my problem
when i "print", "export", or "find" in the crystal report viewer it will prompt me to log in in the server.


code in webform1

<pre><pre lang="HTML">
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Reporting;

namespace WebApplication9
{

    public partial class WebForm1 : System.Web.UI.Page
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["listoq"].ConnectionString);
        ReportDocument rdoc = new ReportDocument();


        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            cn.Open();
            SqlConnection cs = new SqlConnection("data source=.; database=palistuhan; integrated security=SSPI");
            SqlCommand cmd = new SqlCommand("listoproce", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable ds = new DataTable();
            da.Fill(ds);
            rdoc.Load(Server.MapPath("CrystalReport1.rpt"));
            rdoc.SetDataSource(ds);
            rdoc.SetParameterValue("My Parameter", TextBox1.Text);
            CrystalReportViewer1.ReportSource = rdoc;
            CrystalReportViewer1.DataBind();
            cn.Close();
        }

    }
}

see picture below
http://i1228.photobucket.com/albums/ee443/jaylisto/q1_zpswrwmzwoc.png
Posted
Updated 9-Mar-15 1:36am
v5
Comments
santosh_131 5-Mar-15 14:47pm    
Does table name for the datatable and in the report schema(in Field Explorer -under DatabaseFields) match?? it some times happens to me if they do not match. And also the fields layed out in the report should exist in the datatable retrieved from database.

1 solution

C#
crystalReport.Load(Server.MapPath("~/CrystalReport1.rpt"));
    Customers dsCustomers = GetData("select top 5 * from customers");
    crystalReport.SetDataSource(dsCustomers);
    CrystalReportViewer1.ReportSource = crystalReport;
 
Share this answer
 
v2

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