Click here to Skip to main content
16,020,822 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
rptReport1 objrptcsp2 = new rptReport1();
objrptcsp2.Subreports[0].SetDataSource(dsTemp.Tables[0]);
objrptcsp2.SetDataSource(dsTemp.Tables[0]);


Note: Hi I m trying to Bind Crystal Report Viewer Dynamically from the above code, but it will give data of only view created in database and drag and drop placed in my .rpt file.

Is that any valid Solution for this Problem?????
Posted

1 solution

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
CrystalReport1 report = new CrystalReport1();
TableLogOnInfo info = new TableLogOnInfo();
private void crystalReportViewer1_Load(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
info.ConnectionInfo.DatabaseName = "Adventureworks";
info.ConnectionInfo.ServerName = ".";
info.ConnectionInfo.UserID = "sa";
info.ConnectionInfo.Password = "niit#123";
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=adventureworks;User id=sa;Password=niit#123");
con.Open();
string query = "select firstname,lastname from person.contact where firstname like 'z%'";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
report.Database.Tables[0].ApplyLogOnInfo(info);
report.Database.Tables[0].SetDataSource(dt);
crystalReportViewer1.ReportSource = report;

}
}
}
//Add a Crystal Report to ur project
//Select as a Blank Report
//Right Click on Database Fields
//Click Database Expert
//Create New Connection
//Click OLEDB (ADO)
//Make New Connection
//Give All the Required Details for making Connection
 
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