如何使用C#在VS2008中更改Crystal Report中的SQL查询? [英] How to change SQL Query in Crystal Report in VS2008 with C#?

查看:81
本文介绍了如何使用C#在VS2008中更改Crystal Report中的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想动态地将数据源设置为C#Winform应用程序中的Crystal Report ..

但是当我创建时使用使用报告向导的水晶报告,它显示水晶报告中的所有记录字段..



我检查了SQL查询水晶报告 - >右键单击Field Explorer中的Database Fields,然后单击Show SQL Query ...

显示简单连接,从两个表中获取所有记录..



如何动态设置SQL查询???



当我调用Crystal报表时,我试图设置数据集,但是它不起作用...... :-(

我的C#代码是: -

Hi,

I want to set data source dynamically to a Crystal Report in C# Winform application..
But when I create the crystal report with "Using the Report Wizard", it shows all records fields in crystal report..

I checked the SQL Query in Crystal Report -> Right click on "Database Fields" in Field Explorer and then click on "Show SQL Query..."
It show simple connection, which fetch all records from two tables..

How to set that SQL Query dynamically???

I tried to set dataset, when I call the Crystal report, but it does not worked... :-(
My C# code is :-

OleDbConnection con = new OleDbConnection("Provider=Microsoft.jet.oledb.4.0; data source=" + Application.StartupPath + @"\DataInfo1.mdb;Persist Security Info=true;User Id='Admin'; password=;");

con.Open();

OleDbDataAdapter da = new OleDbDataAdapter(@"SELECT ct.custID, c.custName, c.custAdd,ct.custTranDate,ct.custTranType,ct.custPaidAmt,ct.custDueAmt, c.custArea FROM custTransaction ct left JOIN custDetails c ON ct.custID = c.custID where ct.custID='CUST-000002' and ct.custTranDate BETWEEN #2/28/13# AND #3/1/13#", con);  
          
DataSet ds = new DataSet();
da.Fill(ds);

CrystalReport1 cr = new CrystalReport1();
cr.SetDataSource(ds);
this.crystalReportViewer1.ReportSource = new CrystalReport1();
this.crystalReportViewer1.Show();



请帮助我。



感谢高级。


Please help me.

Thanks in Advanced.

推荐答案

你的问题已经结束了

u r problem is over here
this.crystalReportViewer1.ReportSource = new CrystalReport1();



u必须按如下方式使用


u have to use as follows

this.crystalReportViewer1.ReportSource = cr;
this.crystalReportViewer1.Refresh();



希望它能帮助

还查看以下链接...

http://csharp.net-informations.com/crystal- reports / csharp-dynamic-crystal-reports.htm [ ^ ]


这篇关于如何使用C#在VS2008中更改Crystal Report中的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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