Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
im trying to display data from multiple tablesinto single report with the simple query with joins but when i am running bpage then the crystal report is completly empty means its not fetching data from database,but when i am execeuting that query in sql server it shows me a proper result
the query is as bellw
C#
create proc FetchInvoice
(@invoiceNo numeric(10) )
as
begin
  SELECT c.CompanyName,c.ExciseNo,c.VATNo,c.CSTNo,c.CompanyId,
		   com.AddressId,com.AddressLine1,com.CompanyCity,com.Country,com.Pin,com.State,
		   cust.Cust_First_Name,cust.Cust_Last_Name,cust.ContactNo,cust.EmailId,
		   h.CustomerPONo,h.Fi_Year,h.FinalInvoicePrice,
		   h.FinalInvoicePrice_WithoutRO,h.inv_date,h.invoice_no,
		   h.RO_Fact,h.TaxPrice,h.TaxTerms,h.CompanyId,
		   l.Item,l.Description,l.Quantity,l.TeriffClass,l.Unite_Price,l.Total_Price
           FROM company_master c          
           INNER JOIN 
		   companyaddress AS Com
           ON c.CompanyId=Com.AddressId
		   INNER JOIN customeraddress as cust
		   on c.CompanyId=cust.Cust_Add_Id
		   inner join Header as h
		   on c.CompanyId=h.CompanyId 
		  inner join invoiceItems as l
		    on h.invoice_no=l.invoice_no
		   where h.invoice_no=@invoiceNo
end



and the code which i am using to show this report is as bellow
C#
int invNo = 1;
SqlConnection con = new SqlConnection(CS);
SqlCommand cmd = new SqlCommand();
TaxInvoice ds = null;
SqlDataAdapter adapter;
try
{
    con.Open();
    cmd.CommandText = "FetchInvoice";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@invoiceNo", invNo);
    cmd.Connection = con;
    cmd.ExecuteNonQuery();
    ds = new TaxInvoice();
    adapter = new SqlDataAdapter(cmd);
    adapter.Fill(ds);
    ReportDocument rd = new ReportDocument();
    rd.Load(Server.MapPath("Invoicereport.rpt"));
    rd.SetDataSource(ds.Tables[1]);
    CrystalReportViewer1.ReportSource = rd;
}
catch (Exception ex)
{
    throw new Exception(ex.Message);
}


but at the end i am getting is empty report
can any one help me regarding this issue??
thanks in advance
Posted
Comments
Richard Deeming 28-Jan-16 9:58am    
throw new Exception(ex.Message);

Don't do that. You've just destroyed the stack trace and type information, and made it impossible for calling code to catch the exception without using a catch-all block.

Either use:
throw new SomeSpecificExceptionType(ex.Message, ex);

Or:
throw;

Or just remove the try..catch block, since you're not handling the exception at all.
Sinisa Hajnal 28-Jan-16 10:38am    
I second Richard Deeming on exception handling :)

As for your report, did you try SetDataSource(ds)? Did you set a breakpoint and confirmed that Tables[1] actually contains data? What is TaxInvoice class? Just a wrapper for dataset or something more advanced?
Madhav Gunjal 28-Jan-16 23:40pm    
taxinvoice is a name of dataset, and when m setting breakpoint the table shows only fields not a data

1 solution

ExecuteNonQuery does not return row data, only the number of rows affected.
Refer to the below link;
Execute Non Query Documentation
I would recommend using ExecuteReader - refer to the below link;
Execute Reader Documentation
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900