使用上次Datetime获取数据

时间:2012-10-30 06:13:19

标签: c# asp.net sql sql-server stored-procedures

我必须在gridview中将这些详细信息显示为Tempname作为唯一且相关的日期时间在drodown中,最后一次按名称在标签中运行。无法上传表格图片,因为我没有足够的声誉。

    private void GridLoading()
    {
        DataSet ds = new DataSet();
        ds = Common.LoadingGrid();
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataSet ds = new DataSet();
            Label lblName = e.Row.FindControl("Label1") as Label;
            ds = Common.RunByDate(lblName.Text);
            DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;

            ddl.DataTextField = "RunDate";
            ddl.DataValueField = "RunDate";
            ddl.DataSource = ds;
            ddl.DataBind();
            var items = ddl.Items;
          }           
    }

但是我无法在标签中获得Runby名称。如何显示它?以下是我的存储过程

    Select distinct TempName from SV_JobHistoryTable 

    SELECT TempName,RunDate
    FROM SV_JobHistoryTable  where TempName=@tempname 

3 个答案:

答案 0 :(得分:0)

到目前为止,我所理解的是,您希望Unique TempName获得Lastest RunDate,您只需要此查询:

SELECT RunByName, MAX(RunDate)
FROM SV_JobHistoryTable  
WHERE TempName = @tempname 
GROUP BY RunByName

答案 1 :(得分:0)

试试这个:

SELECT TempName,RunDate,max(Runbyname)
    FROM SV_JobHistoryTable  where TempName=@tempname 
    group by TempName,RunDate

答案 2 :(得分:0)

这是你想要的吗?

    SELECT TOP 1
         RunByName, RunDate
    FROM 
        SV_JobHistoryTable 
    WHERE 
        TempName = @tempname                    
    ORDER BY 
        RunDate DESC    

或者您想记录的条目多于一个?