Crystal Report抛出错误

时间:2017-10-04 08:17:19

标签: c# .net crystal-reports

我写了一段代码而且它给出了错误。

这是我的数据库任务方法:

public DataTable GetInvoiceHeader(string vId)
{
    DataTable dt = new DataTable();
    using (MySqlConnection cn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["icddrb_tblabConnectionString"].ToString()))
    {
        String sSQL = string.Format(@"SELECT cn.`center_name`
                                            ,cn.`center_address`
                                            ,cn.`mobile_no` `center_mobile` 
                                            ,inv.`invoice_id`
                                            ,pt.`pid`
                                            ,inv.`invoice_date`
                                            ,pt.`p_name`
                                            ,pt.`age`
                                            ,pt.`age_unit`
                                            ,pt.`sex`
                                            ,pt.`ref_by`
                                            ,pt.`mobile`
                                            ,un.`full_name` prepared_by
                                            ,inv.sample_name, inv.collection_date_time
                             FROM  `tb_invoice` inv 
                             INNER JOIN `tb_patient` pt ON inv.`parient_id` =  pt.`id` AND inv.id = {0}
                             INNER JOIN `tb_center` cn ON inv.`center_id` = cn.`id`
                             INNER JOIN `tb_user` un ON inv.`prepared_by` = un.`id`", vId);

        MySqlDataAdapter da = new MySqlDataAdapter(sSQL, cn);

        da.Fill(dt);
        da.Dispose();
    }
    return dt;
}

我从这里调用DB方法:

ReportDAL rDal = new ReportDAL();
receipt r = new receipt();


//  DataTable dm = rDal.GetInvoiceHeader(vId);
//string ww = GetInvoiceHeader(vId);

r.Database.Tables["ReceiptHeader"].SetDataSource(rDal.GetInvoiceHeader(vId));
r.Database.Tables["ReceiptDetails"].SetDataSource(rDal.GetInvoiceDetails(vId));
r.SetParameterValue("pReportDeliveryTime", GlobalData.reportDeliveryTime);
crystalReportViewer1.ReportSource = r;

我调试代码并在执行时看到:r.Database.Tables["ReceiptHeader"].SetDataSource(rDal.GetInvoiceHeader(vId));

它会抛出错误。但是数据表包含数据。

错误是:

  

' CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass'至   界面类型   ' CrystalDecisions.ReportAppServer.Controllers.ISCRReportSource&#39 ;.这个   操作失败,因为QueryInterface调用COM组件   用于与IID' {98CDE168-C1BF-4179-BE4C-F2CFA7CB8398}'的接口   由于以下错误而失败:不支持此类接口   (HRESULT异常:0x80004002(E_NOINTERFACE))。

1 个答案:

答案 0 :(得分:0)

从DataAdaptor填写时,您必须使用DataSet,当您返回时,您必须选择要返回的表

public DataTable GetInvoiceHeader(string vId)
{
    DataSet ds = new DataSet();
    using (MySqlConnection cn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["icddrb_tblabConnectionString"].ToString()))
    {
        String sSQL = string.Format(@"SELECT cn.`center_name`
                                            ,cn.`center_address`
                                            ,cn.`mobile_no` `center_mobile` 
                                            ,inv.`invoice_id`
                                            ,pt.`pid`
                                            ,inv.`invoice_date`
                                            ,pt.`p_name`
                                            ,pt.`age`
                                            ,pt.`age_unit`
                                            ,pt.`sex`
                                            ,pt.`ref_by`
                                            ,pt.`mobile`
                                            ,un.`full_name` prepared_by
                                            ,inv.sample_name, inv.collection_date_time
                             FROM  `tb_invoice` inv 
                             INNER JOIN `tb_patient` pt ON inv.`parient_id` =  pt.`id` AND inv.id = {0}
                             INNER JOIN `tb_center` cn ON inv.`center_id` = cn.`id`
                             INNER JOIN `tb_user` un ON inv.`prepared_by` = un.`id`", vId);

        MySqlDataAdapter da = new MySqlDataAdapter(sSQL, cn);

        da.Fill(ds);
        da.Dispose();
    }
    return ds.Table[0];
}