Skip to Content
Former Member
Dec 13, 2006 at 03:54 AM

Help with dynamic datasource and record selection


<span>Hi, I&#39;m having some difficulty with part of an application I&#39;m trying to build, but here&#39;s some background first.<br /> <br /> I am a student at the University of Maryland, and I&#39;m writing an application for one of the departments here at the university. It is sort of a front-end for an access database with a lot of extra functionality. This includes reports. First of all, the user can change the databse that the application uses, so I store that in an appsetting. For this reason, I have to tell the report what database to use at runtime rather than using the database expert. I am building a sort of report wizard in which the user selects certain values, and based upon those values, the SQL statement that the report gets data from changes. So almost everything about the report&#39;s data is dynamic and will be determined at runtime. <br /> <br /> So for example if the user chooses an officer report by chapter names, I do this (chapters is a comma delimited string):<br /> <br /><span style="font-weight: bold"> string sel = "SELECT * FROM [Undergrad Leadership] WHERE [Leadership Position] = &#39;" + txtPosition.Text + "&#39; AND [Chapter Name] IN (" + chapters + ");";</span><br /> <br /> The part I am lost on, is how to actually interface with crystal reports. In the following code, conn is an OleDbConnection to the correct database, rep is the ReportDocument, and view is a CrystalReportsViewer.<br /> <br /><span style="font-weight: bold"> rep.DataSourceConnections[0].SetConnection(conn.DataSource, conn.Database, false); <br /> rep.RecordSelectionFormula = sel;</span><br /><span style="font-weight: bold"> view.ReportSource = rep;</span><br /> <br /> When I try to load the report, I get the following error message:<br /> Error in formula <Record Selection>: a number, currency amount, boolean, date, time, date-time, or string is expected here.<br /> <br /> Also, assuming this formula gets fixed, how do I actually get fields from this formula and datasource onto my report, since I can&#39;t do it at design time? Thanks in advance for the help.<br /> <br /> -Jared<br /> </span>