动态数据源和记录选择

动态数据源和记录选择

本文介绍了动态数据源和记录选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个应用程序的一部分有一些困难,但这里有一些背景知识。



我是大学的学生马里兰州,我正在为大学的一个部门写一个
的申请。
对于具有大量额外
功能的访问数据库来说是一种前端。这包括报告。首先,
用户可以更改应用程序使用的数据库,因此我将
存储在appsetting中。出于这个原因,我必须告诉报告在运行时使用什么
数据库而不是使用数据库专家。
我正在构建一种报告向导,其中用户选择某些
值,并根据这些值,报告
从更改中获取数据的SQL语句。因此几乎关于报告的
数据的所有内容都是动态的,并将在运行时确定。



例如,如果用户按章节名称选择官员报告,我这样做(章节是逗号分隔的字符串):



string sel =" SELECT * FROM [Undergrad Leadership] WHERE [Leadership
Position] ='" + txtPosition.Text +"'和[章节名称] IN(" +
章节+");" ;;




部分我迷失了,是如何实际与水晶
报告的接口。在下面的代码中,conn是
正确数据库的OleDbConnection,rep是ReportDocument,view是
CrystalReportsViewer。



rep.DataSourceConnections [0] .SetConnection(conn.DataSource,conn.Database,false);

rep.RecordSelectionFormula = sel;


view.ReportSource = rep ;




当我尝试加载报告时,收到以下错误消息:

公式中的错误<记录选择>:这里有一个数字,货币
金额,布尔值,日期,时间,日期时间或字符串。



另外,假设这个公式得到修复,怎么做我实际上从这个公式和数据源获得字段
到我的报告中,因为我不能在
设计时间做到这一点?在此先感谢您的帮助。



-Jared

解决方案

Hi, I'm having some difficulty with part of an application I'm trying to build, but here's some background first.

I am a student at the University of Maryland, and I'm writing anapplication for one of the departments here at the university.  Itis sort of a front-end for an access database with a lot of extrafunctionality.  This includes reports.  First of all, theuser can change the databse that the application uses, so I store thatin an appsetting.  For this reason, I have to tell the report whatdatabase to use at runtime rather than using the database expert. I am building a sort of report wizard in which the user selects certainvalues, and based upon those values, the SQL statement that the reportgets data from changes.  So almost everything about the report'sdata is dynamic and will be determined at runtime. 

So for example if the user chooses an officer report by chapter names, I do this (chapters is a comma delimited string):

string sel = "SELECT * FROM [Undergrad Leadership] WHERE [LeadershipPosition] = '" + txtPosition.Text + "' AND [Chapter Name] IN (" +chapters + ");";

The part I am lost on, is how to actually interface with crystalreports.  In the following code, conn is an OleDbConnection to thecorrect database, rep is the ReportDocument, and view is aCrystalReportsViewer.

rep.DataSourceConnections[0].SetConnection(conn.DataSource, conn.Database, false);
rep.RecordSelectionFormula = sel;

view.ReportSource = rep;

When I try to load the report, I get the following error message:
Error in formula <Record Selection>:  a number, currencyamount, boolean, date, time, date-time, or string is expected here.

Also, assuming this formula gets fixed, how do I actually get fieldsfrom this formula and datasource onto my report, since I can't do it atdesign time?  Thanks in advance for the help.

-Jared

解决方案


这篇关于动态数据源和记录选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:04