如何显示来自两个不同表的日期?

how to display dates from two different tables?

在 DataView 中,我显示了来自数据库中两个不同 table 的两个日期。维修服务日期 table 和检查清单日期来自 fleetchecklist table。 这两列在数据库 tables 中都称为日期。问题是它只显示一个日期(清单日期)。服务日期应该是 14/06/2015。

当我在 MySql Workbench

中 运行 时,SQL 查询有效
 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

我的其他日期代码是:

    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> 

您正在将清单日期和服务日期分配给同一日期 属性。这应该有效:

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>