0

I'm developing an automation of manual system for a fuel pump. Up till now I've accomplished my tasks but now I'm stuck on something related to retrieve data from multiple related tables into one data grid view. I've already 'Google' my problem but failed to find the right way to move on. Here is my scenario Explanation:

  • I've table named 'Department' which have 'Vehicles' table; (1-*) relation.
  • then 'Vehicles' table have 'Months' table to keep monthly billing details; (1-*) relation.
  • and 'Months' table have tow tables 'Fuel_Bill' and 'Lubi_Bill' to keep the top level information of bills.(Both have 1-1 relation with 'Months' table).

I've build this using entity-framework designer first model on SQL LocalDB.

So, now I'm stuck on showing: -Department's monthly abstract view which have the details related to 'Vehicles' and the 'Fuel _bill" details of selected 'Month' in one data grid view.

It's a long question but to be clear I give these details, Please help me out, my whole project will fail if I can't accomplish this.

Any help will be appreciated. Thanks in advance.

I'm adding links to pictures of my data base structure.

Entity Framework model:

Model

And what I'm trying to achieve:

View

1
  • 4
    What is the actual question here? Can you provide a SQL Fiddle to help us visualize your data, and can you show your desired results? I understand you basically want a query, but with what you have posted, there's nothing anyone can do to help you. Commented Mar 9, 2014 at 23:21

1 Answer 1

1

I would start from context.Months to collect the required data for your grid:

var viewModels = context.Months
    .Where(m => m.Month_Name == selectedMonthName &&
        m.Vehical.Dept_Id == selectedDepartmentId)
    .Select(m => new
    {
        Vehc_Number = m.Vehical.Vehc_Number,
        FB_Id = m.Fule_Bill.FB_Id,
        LB_GTAmount = m.Fule_Bill.LB_GTAmount,
        LB_GTQuantity = m.Fule_Bill.LB_GTQuantity
    })
    .ToList();

viewModels will be a list of anonymous objects with those four properties that you want to show in the grid. It should be possible to bind this list to the grid view.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Slauma from deep of my heart, I really appreciate and value your effort and time for me, I give you a 10+ vote (unfortunately Can't vote higher then 1). May I ask you for one thing more favor that if I want to show the details from Lubi_Bill table in the same gridview how should I suppose to do that? do I need to add another column which shows the details With Lubi_Bill Id? any idea on how to do that please suggest me. Once thanks agian B-)
here is the link what I'm trying to do now thanks, drive.google.com/file/d/0BxhchZSm5cWnbkdOM1FtSXZFbHc/…
@CaptivativeMortal: You would add more properties into the Select block, like LB_GTAmount2 = m.Lubricant_Bill.LB_GTAmount, etc.
I've already tried that but this shows no records in datagridview :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.