Crystal Report and Requests

T

Téo

I don't see my question with my newsreader, just try to post a last time,
sorry if it's (one more...) bug of OE...

Hi,

I have created a crytal report based on a table of my SQL Server. Everything
works fine.
I would like now to fill my report with a sql request in the code behind
instead of the table in the crystal report.
But in the following code, the dataset created isn't "used" by the crystal
report wich continues to use the table.
And if i delete the table in the crystal report to use unbound fields, it
doesn't work.

Any idea?

myCR = new CrystalReport1();
myCR.SetDatabaseLogon("sa", "mypassword");
SqlConnection cn=new SqlConnection(accessbdd.chaineSQL);
SqlCommand cmd=new SqlCommand();
cmd.Connection=cn;
cmd.CommandText="SELECT TOP 10 * FROM Table1";
cmd.CommandType=CommandType.Text;
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
myCR.SetDataSource(ds);
CrystalReportViewer1.ReportSource=myCR;

Thanks.
 
G

Guest

Hi,

If you want to use a DataSet as datasource for a crystal report, you need to
create a typed dataset and use this typed dataset when designing the report.

Then, from your code behind, you can create an instance of the typed dataset
and fill with the data. Then call this method.

myCR.SetDataSource(ds);

There is no need for calling SetDatabaseLogon("sa", "mypassword");
 
G

Guest

In my experience, it’s better to use datatable rather than dataset as CR’s
data source.

HTH

Elton Wang
(e-mail address removed)
 
T

Téo

Thanks, do you have a tutorial link or an example ?
In fact, the request on wich the CR is based, is changing ("WHERE num_id>" +
TB1.Text, for example), so i don't want to create the source of the CR at
"design time".
I have to do it dynamically in the code behind...

Thanks.
 

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