水晶报表动态数据绑定 [英] Crystal Report Dynamic DataBinding

查看:75
本文介绍了水晶报表动态数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rptReport1 objrptcsp2 =新的rptReport1();
objrptcsp2.Subreports [0] .SetDataSource(dsTemp.Tables [0]);
objrptcsp2.SetDataSource(dsTemp.Tables [0]);


注意:我正在尝试从上述代码动态绑定Crystal Report Viewer,但是它将仅提供在数据库中创建的视图的数据,并将其拖放到我的.rpt文件中.

是这个问题的任何有效解决方案吗????????????????????????????? 使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Text;
使用System.Windows.Forms;
使用System.Data.SqlClient;
使用CrystalDecisions.CrystalReports.Engine;
使用CrystalDecisions.CrystalReports;
使用CrystalDecisions.Shared;
命名空间WindowsApplication3
{
公共局部类Form1:Form
{
公共Form1()
{
InitializeComponent();
}
CrystalReport1报告=新的CrystalReport1();
TableLogOnInfo info =新的TableLogOnInfo();
私有void crystalReportViewer1_Load(对象发送者,EventArgs e)
{

}

私有void Form1_Load(对象发送者,EventArgs e)
{
info.ConnectionInfo.DatabaseName ="Adventureworks";
info.ConnectionInfo.ServerName =.";
info.ConnectionInfo.UserID ="sa";
info.ConnectionInfo.Password ="niit#123";
SqlConnection con =新的SqlConnection(数据源= .;初始目录= adventureworks;用户ID = sa;密码= niit#123");
con.Open();
字符串查询=``从person.contact中选择名字,姓氏,其中名字如``z%'''';;
SqlDataAdapter da =新的SqlDataAdapter(query,con);
DataTable dt = new DataTable();
da.Fill(dt);
report.Database.Tables [0] .ApplyLogOnInfo(info);
report.Database.Tables [0] .SetDataSource(dt);
crystalReportViewer1.ReportSource =报告;

}
}
}
//向您的项目添加Crystal Report
//选择为空白报告
//右键单击数据库字段
//单击数据库专家
//创建新的连接
//单击OLEDB(ADO)
//建立新连接
//提供建立连接所需的所有详细信息


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

解决方案

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


这篇关于水晶报表动态数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆