how to display dates from two different tables?

46 views Asked by At

In a DataView I am displaying two dates from two different tables in a database. Service date from maintenance table and Checklist date from fleetchecklist table. Both columns are called Date in the database tables. The problem is its only displaying one date (checklist date). Service date should say 14/06/2015.

enter image description here

The SQL query works when I run it in MySql Workbench

 SELECT checklistitem.*,
          cl.Date As ChecklistDate,
          m1.Date AS Date
    FROM checklistitem
    LEFT JOIN maintenance m1 ON m1.CheckListID 
    LEFT JOIN Vehicle v ON m1.LinkedID = v.ID
    LEFT JOIN Trailer t ON m1.LinkedID = t.ID 
    LEFT JOIN GeneralSmall gs ON m1.TypeID = gs.ID
    LEFT JOIN fleetchecklist cl ON m1.ChecklistID = cl.ID
    WHERE m1.Company_ID = 129

Other code I have for the dates are:

    public DateTime Date { get; set; }
    public DateTime ChecklistDate { get; set; }

    protected override void FillObject(DataRow dr)
   {
                    if (dr["Date"] != DBNull.Value)
                        Date = Convert.ToDateTime(dr["Date"]);
                    if (dr["ChecklistDate"] != DBNull.Value)
                        Date = Convert.ToDateTime(dr["ChecklistDate"]);
   }



 <asp:BoundField DataField="Date" HeaderText="Service Date" SortExpression="Date"  dataformatstring="{0:dd/MM/yyyy}"></asp:BoundField>
<asp:BoundField DataField="Date" HeaderText="Checklist Date" SortExpression="ChecklistDate"  dataformatstring="{0:dd/MM/yyyy}"></asp:BoundField> 
1

There are 1 answers

0
rageit On BEST ANSWER

You are assigning Checklist date and Service date to the same Date property. This should work:

public DateTime Date { get; set; }
public DateTime ChecklistDate { get; set; }

protected override void FillObject(DataRow dr)
{
    if (dr["Date"] != DBNull.Value)
        Date = Convert.ToDateTime(dr["Date"]);
    if (dr["ChecklistDate"] != DBNull.Value)
        ChecklistDate = Convert.ToDateTime(dr["ChecklistDate"]);
}


<asp:BoundField DataField="Date" HeaderText="Service Date" SortExpression="Date"  dataformatstring="{0:dd/MM/yyyy}"></asp:BoundField>
<asp:BoundField DataField="ChecklistDate" HeaderText="Checklist Date" SortExpression="ChecklistDate"  dataformatstring="{0:dd/MM/yyyy}"></asp:BoundField>