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

时间:2015-06-17 13:35:14

标签: c# mysql visual-studio dataview

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

enter image description here

当我在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> 

1 个答案:

答案 0 :(得分:3)

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

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>