Crystal Report Throw error

0

I wrote a code and it gives error.

Here my db task method:

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;
}

And I call DB method from here:

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;

I debug code and saw, when execution comes to: r.Database.Tables["ReceiptHeader"].SetDataSource(rDal.GetInvoiceHeader(vId));

it throws an error.But datatable contain data.

error is:

'CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass' to interface type 'CrystalDecisions.ReportAppServer.Controllers.ISCRReportSource'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{98CDE168-C1BF-4179-BE4C-F2CFA7CB8398}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

c#
.net
crystal-reports
asked on Stack Overflow Oct 4, 2017 by (unknown user) • edited Oct 4, 2017 by imsome1

1 Answer

0

when you fill from the DataAdaptor, you have to use DataSet and when you return you have to select which table to return

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];
}

User contributions licensed under CC BY-SA 3.0