开发者

Crystal Reports and strongly typed datasets yields empty report

I am converting an ASP.Net app from VS 2003 to VS 2005 as a starting point. The app uses Crystal Reports and binds using ADO.Net to a strongly typed dataset (XSD). I had to change some of Crystal Code to work with the newer version of Crystal. Now, when I run the page, the report generates, but none of the fields fill in. I have seen lots of people having the same problem with no real solutions out there. I decided to create a fresh project that does the same thing to remove the conversation from VS 2003 to 2005 as a possible cause of the problem. So my sample program has a button that runs a query, fills the dataset and assigns it to the report开发者_如何转开发. The report displays the headers only. The code is below. I have no idea what to try next.

    DataSet1 ds = new DataSet1();

    SqlConnection conn = 
       new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

    SqlDataAdapter da = new SqlDataAdapter("select * from mytable", conn);
    da.Fill(ds);

    ReportDocument rep = new ReportDocument();
    rep.Load(Server.MapPath("crystalreport.rpt"));
    rep.SetDataSource(ds);

    CrystalReportViewer1.ReportSource = rep;
    CrystalReportViewer1.RefreshReport();

I also created the DataSet1.XSD based on the same MYTABLE table. I get no errors or any indication anything is wrong except that the fields in the report don't populate.


It would take some debugging to know for sure why it's not working for you. Have you looked at the resulting dataset in a debugging session, and seen if it fills correctly?

Here's a good example of a method to work from.

SqlConnection cnn;
string connectionString = null;
string sql = null;

connectionString = "data source=SERVERNAME;initial catalog=DATABASENAME;user id=USERNAME;password=PASSWORD;";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select * from mytable";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "mytable");
cnn.Close();

CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜