2012-07-13 67 views
1
create procedure St_Proc_GetUserReportforCurrentDayTask     
@userID int     
as     
    Begin     
     set NoCount on;     
     DECLARE @TODAY DATE      
     SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)     
     select CONVERT(VARCHAR,production.CalendarDate,101) + RIGHT (CONVERT(VARCHAR,production.CalendarDate , 100) ,7) as Date,     
     RegionAndProjectInfo.RegionProjectName as Region ,     
     County.CountyName as County,     
     WorkType.WorkTypeName as WorkType,     
     Task.TaskName as Task,  
     Production.VolumeProcessed as 'Volumes Processed',     
     Production.TimeSpent as 'Duration(HH:MM)'     
     from Production     
     inner join RegionAndProjectInfo     
     on     
     RegionAndProjectInfo.RegionProjectID=Production.RegionProjectID     
     inner join County     
     on     
     County.CountyID=Production.CountyID     
     inner join WorkType     
     on     
     WorkType.WorkTypeID=Production.WorkTypeID     
     inner join Task     
     on     
     Task.TaskID=Production.TaskID     
     where [email protected] and CalendarDate >= @TODAY     
    End 

這是我的存儲過程,我在執行這個存儲過程和結果保存在數據集中,然後結合與網格這個數據集。FIX-數據綁定:「System.Data.DataRowView」不包含屬性名稱爲

private void BindGridOnPageLoad() 
    { 
     _production = new EmployeeQuotientCL.Production(); 
     _userEcode = Convert.ToString(Session["UserID"]); 
     int _userID = _production.GetUserIDFromDB(_userEcode); 
     dsUserTaskDetails = _production.GetTabularUsertaskDetails(_userID); 
     BindGridView(dsUserTaskDetails); 
    } 

到這裏的每一件事情是好的。於是我得到了規定,以顯示時間(HH:MM)總網格view.I又增加了在頁面下面的代碼的頁腳: -

<div id="gridview"> 
      <asp:GridView ID="GVUserEnteredDetails" runat="server" ShowFooter="true" CssClass="mGrid" CellSpacing="2" onselectedindexchanged="GVUserEnteredDetails_SelectedIndexChanged" onrowdatabound="GridView1_RowDataBound">     
      </asp:GridView> 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      tp += Convert.ToDecimal(((DataRowView)e.Row.DataItem).Row["[Duration(HH:MM)]"]); 
     } 
     if (e.Row.RowType == DataControlRowType.Footer) 
     { 
      e.Row.Cells[0].Text = "Total Hours : "; 
      e.Row.Cells[1].Text = tp.ToString("c"); 
      e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Right; 
      e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right; 
      e.Row.Font.Bold = true; 

     } 
    } 

但是,當我調試即時得到這個錯誤: - 「數據綁定:‘System.Data.DataRowView’不包含名爲‘時間’的屬性。」我在做什麼錯誤以及如何解決它?任何建議和幫助將對我有所幫助。

堆棧跟蹤: -

[ArgumentException: Column '[Duration(HH:MM)]' does not belong to table Table.] System.Data.DataRow.GetDataColumn(String columnName) +2124943 System.Data.DataRow.get_Item(String columnName) +13 EQ.Associates.Production.GridView1_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\Users\dsingh\Documents\Visual Studio 2010\Projects\EQ\EQ\Associates\Production.aspx.cs:112 System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) +115 System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +181 System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3896 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66 System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 EQ.Associates.Production.BindGridView(DataSet ds) in C:\Users\dsingh\Documents\Visual Studio 2010\Projects\EQ\EQ\Associates\Production.aspx.cs:603 EQ.Associates.Production.BindGridOnPageLoad() in C:\Users\dsingh\Documents\Visual Studio 2010\Projects\EQ\EQ\Associates\Production.aspx.cs:593 EQ.Associates.Production.Page_Load(Object sender, EventArgs e) in C:\Users\dsingh\Documents\Visual Studio 2010\Projects\EQ\EQ\Associates\Production.aspx.cs:78 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

+0

你是右表綁定到'GridView'什麼? – V4Vendetta 2012-07-13 10:48:22

+0

是的,我指定在我的問題,直到數據綁定和只顯示網格的每件事情都工作正常,但因爲我曾嘗試添加頁腳,然後我得到這個錯誤。 – 2012-07-13 10:52:42

+0

有點令人驚訝,你的'DataSource'顯示'持續時間......'(希望程序與你正在執行的過程相同) – V4Vendetta 2012-07-13 11:23:09

回答

1

正如你在你面對你已表示爲HH數據的小數解析麻煩的評論提到:毫米

你應該使用TimeSpan總結所有這些值,而不是小數點。 (TimeSpan具有從4.0解析確切的功能,但如果你是在一個較小的版本)

嘗試以這種方式

TimeSpan ts = DateTime.ParseExact("02:30", "HH:mm", CultureInfo.InvariantCulture).TimeOfDay; 
// instead of 02:30 you would have the string from your column passed in 

// you can add up the values in this fashion 
ts.Add(DateTime.ParseExact("08:30", "HH:mm", CultureInfo.InvariantCulture).TimeOfDay); 

產生的時間跨度做它,你可以用它來顯示它您選擇,因爲它會與格式也有天數太多,或者你可以隨時顯示ts.TotalMinutes

希望這是你尋找出別的請更新相關部分

+0

是的,其實我正在尋找。現在我可以在頁腳中填充總數。非常感謝 – 2012-07-16 11:56:58

0

嘗試使用在你的列名sqare支架,因爲它含有特殊字符。像,

tp += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "[Duration(HH:MM)]")); 
+0

按照你的做法,但是這個我得到這個異常「異常已被調用的目標拋出。」 – 2012-07-13 11:09:07

+0

你能發表詳細的異常堆棧跟蹤嗎? – 2012-07-13 11:23:36

+0

您甚至可以嘗試:tp + = Convert.ToDecimal(((DataRowView)e.Row.DataItem).Row [「[Duration(HH:MM)]」)。但是它假定您使用Datatable或Dataset作爲數據源。 – 2012-07-13 11:26:06

相關問題