locked
How To create a Crystal report with multiple tables RRS feed

  • Question

  • I have created a crystal report with one table it runs, if  i pass more than one table src in sqlDataAdapter.fill(); it donot show records.

    bellow is my code please response

    string info = ConfigurationManager.ConnectionStrings["KiranTradersContext"].ConnectionString;

                SqlConnection mycon = new SqlConnection(info);
                mycon.Open();
                string sql = "SELECT dbo.Customer.Name, dbo.Product.ProductType, dbo.Sale.Date, dbo.Sale.City, dbo.Sale.Mobile, dbo.Sale.TruckNo, dbo.Sale.Packets, dbo.Sale.Weight, dbo.Sale.Rate, dbo.Sale.Total FROM  dbo.Customer INNER JOIN dbo.Sale ON dbo.Customer.CustomerID = dbo.Sale.CustomerID INNER JOIN dbo.Product ON dbo.Sale.ProductID = dbo.Product.ProductID";
                SqlCommand cmd = new SqlCommand(sql, mycon);
                
                Reporting ds = new Reporting();
               
                SqlDataAdapter myda = new SqlDataAdapter(cmd);
               
                myda.Fill(ds,"Sale,Customer,Product");
                         
                     // if i pass here one table src it runs 
                    //is there any way to dispaly two table here. i have used join query here
                                                     
                
                    ReportDocument myrpt = new ReportDocument();
                myrpt.Load(Server.MapPath("~/Reports/Saleone.rpt"));
                myrpt.SetDataSource(ds);
                 
           
                CrystalReportViewer1.ReportSource = myrpt;
                CrystalReportViewer1.DataBind();

    • Moved by Caillen Monday, June 8, 2015 8:20 AM
    Saturday, May 30, 2015 10:46 AM

Answers

  • You can post crystal report issue to Crystal Report Forum, such issues are discussed heavily on that forum.


    Fouad Roumieh

    • Proposed as answer by Caillen Monday, June 1, 2015 3:05 AM
    • Marked as answer by Just Karl Thursday, June 11, 2015 10:10 PM
    Saturday, May 30, 2015 2:13 PM

All replies

  • Couple of things you need to understand.

    When you build your report it is against a source of some sort.

    Think of that as being (kind of) a collection of a type.

    So your table or stored procedure output is a bit like a List<t> where t is a type which has a bunch of properties.

    If you build it against a table:

    CREATE TABLE People
     (
     PersonID int,
     LastName varchar(255),
     FirstName varchar(255),
     Address varchar(255),
     City varchar(255)
     );

    Imagine  you include in your report PersonId and LastName.

    Which would be a bit strange, but this is just to explain things.

    You have effectively told your report that it's datasource will have a PersonId of type int and a Lastname of type Varchar.

    If you give it a datasource without them then it will error.

    If you give it a datasource with those fields and some others then it will work but it doesn't do anything with those extra fields - you would need to change the design of your report and use them before they will be reported.

    If you pass in a datasource which is a dataset and that has two sets of data in it, then it will just take one of those.

    .

    Ok, that's the background.

    So if you want a report which will include some other table then you could put your join in your sql there, refresh your report in the designer based on that query and use those fields in your design.

    There is another sort of option with a sub report but the above is the simple option.

    Is that going to work for you?


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Saturday, May 30, 2015 12:51 PM
  • Have you tried to paste you SQL statement in MS SQL Management Studio and see whether there is result returned?

    chanmm


    chanmm

    Saturday, May 30, 2015 1:36 PM
  • You can post crystal report issue to Crystal Report Forum, such issues are discussed heavily on that forum.


    Fouad Roumieh

    • Proposed as answer by Caillen Monday, June 1, 2015 3:05 AM
    • Marked as answer by Just Karl Thursday, June 11, 2015 10:10 PM
    Saturday, May 30, 2015 2:13 PM