I want to display a simple Crystal Report (already, I think this is an oxymoron) in a Windows Form using a dataset (I'd prefer to do all the database work in my code, rather than letting CR do it).
All of my C# code is using Oracle.DataAccess.Client, but when I tried to create a new DataSet, VS said I had to use the Microsoft Oracle object. I did, created a DataSet with one table, EMPLOYEE. I then created my report that lists four items from the table -- no grouping, no counting, just a list.
Then, I created a Windows Form that gathers the required parameters for my query, and using those parameters, build the SQL. I use the SQL to fill the EMPLOYEE table in the DataSet created earlier. If I look, the table has 700+ rows after filling.
Then, I create a report object, set the datasource to the filled dataset, and set the Crystal Reports Viewer's ReportSource to the report. Seems straightforward, no errors. However, when I try to display the new form (that contains the crystalReportViewer), I am presented with a logon dialog box, asking for server, database, username, password. Even if I supply all of these items, it fails to logon. The form containing the viewer is shown, but there is no report.
I tried filling the dataset with the MS Oracle connection/command/dataadapter, but it made no difference. I also tried setting the username/password for each table in the report after the report object was created, but no luck either.
I read Mark Williams comments in
333284 and a couple of other articles as well.
Any thoughts on how to make this work, and/or a better place to ask?
// Create the dataset
DatasetReportPositiveEmployees ds = new DatasetReportPositiveEmployees();
string sSQL = "SELECT DISTINCT empID, empFName, empLName, empAcctNum from Employee " +
"LEFT INNER JOIN TestResult ON empID = testEmployeeID " +
"WHERE (testResult IN (SELECT resultID FROM Result WHERE resultTreatAsPositive=1))";
System.Data.OracleClient.OracleConnection localConn = new System.Data.OracleClient.OracleConnection(settings.ConnectionString);
localConn.Open();
System.Data.OracleClient.OracleCommand localCmd = new System.Data.OracleClient.OracleCommand();
localCmd.Connection = localConn;
localCmd.CommandText = sSQL;
localCmd.CommandType = CommandType.Text;
System.Data.OracleClient.OracleDataAdapter adapter = new System.Data.OracleClient.OracleDataAdapter();
adapter.SelectCommand = localCmd;
adapter.Fill(ds, "EMPLOYEE"); // Name must match name in Dataset
// Create Report
CrystalReportPositiveEmployees report = new CrystalReportPositiveEmployees();
Tried with/without this section
CrystalDecisions.Shared.TableLogOnInfo login = new CrystalDecisions.Shared.TableLogOnInfo();
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
{
login = tbl.LogOnInfo;
login.ConnectionInfo.ServerName = "myComputer";
login.ConnectionInfo.UserID = "myUser";
login.ConnectionInfo.Password = "myPass";
tbl.ApplyLogOnInfo(login);
}
// Tell report to use dataset
report.SetDataSource(ds);
// Create new form, report viewer has been declared public
formReportViewer dlg = new formReportViewer();
dlg.crystalReportViewer1.ReportSource = report;
// No errors, until next command executes
dlg.ShowDialog();
Thanks,
Glenn