C# and runtime data population of a crystal report

T

Thad

I'm new to C# and I was trying to create a Crystal Report. I've
designed a simple report and I've used several methods for attaching
fields to the report at design time. I've used a DataSet that I've
created by add new item, and I've used the add command and used an
actual SQL statement, and I've used the OLEDB ADO and connected to my
database (Access) tables directly.

I have code that will create a query, use that query with an Adapter
and connection, and return a DataSet.

When I call the Report.SetDataSource(FunctionReturnDataSet());

And then call the report viewer the data that is displayed doesn't
change from the design time data that was set up. It's almost as if
the new dataset I loaded with the SetDataSource, isn't even
recognized.

I've looked through several help sources, and I have my code exactly
like they had it, and I still don't get the data in the report that
should be comming over from the query that creates the new data set.

Below is the source I'm working with, thanks in advance for any time
and/or effort to answer this question.



Source Code:

//Set Rpt SQL, creates a SQL statement based on items selected in list
boxes
private void btnReport_Click(object sender, System.EventArgs e)
{
PeriodicCI rptPrdCI = new PeriodicCI();
TransporterData dataTrans = new TransporterData();
frmReportView rptView = new frmReportView();

try
{
dataTrans.setConnection();
rptPrdCI.SetDataSource (dataTrans.GetPrdCIDataSet(SetRptSQL()));
rptView.crView.ReportSource = rptPrdCI;
dataTrans.closeConnection();
rptView.Show();
}
catch (Exception eError)
{
MessageBox.Show((eError.Message), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}


public DataSet GetPrdCIDataSet(string sSQL)
{
OleDbDataAdapter daTmp = new OleDbDataAdapter();
DataSet dsReturn = new DataSet("PrdRptCI");


try
{
odedbTransporterComm.CommandText = sSQL;
daTmp.SelectCommand = odedbTransporterComm;
daTmp.Fill(dsReturn);
}
catch (Exception e)
{
MessageBox.Show((e.Message), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
return dsReturn;
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Did you create the report with a dataset with data?
I have always created the dataset without any data, just the schema and then
at runtime I add the dataset with data just like you did.

It has always worked fine.

Cheers,
 
T

Thad

Yeah, I'm pretty sure that I have. I was in that trial and error mode
for a while, so as far as attaching the data to the report at design
time, so that I can select fields, I've done all the methods that seem
to be available to me - that I'm aware of.

Maybe, instead of my own data set, I need to create a data set (File
-> New Item -> Data -> Data Set (which does the schema?), and then
when I do my adapter and query stuff, I need to fill that dataset?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Did you try to make a run just to get the schema, write the schema using
DataSet.WriteSchema( ... ) and then using this schema as the source for the
report?

I usually do this, instead of creating a dataset visually, it's easier and
you are 100% sure that you will get the same schema when you run it.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Thad said:
Yeah, I'm pretty sure that I have. I was in that trial and error mode
for a while, so as far as attaching the data to the report at design
time, so that I can select fields, I've done all the methods that seem
to be available to me - that I'm aware of.

Maybe, instead of my own data set, I need to create a data set (File
-> New Item -> Data -> Data Set (which does the schema?), and then
when I do my adapter and query stuff, I need to fill that dataset?

"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top