2011-06-05 10 views
0
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using Microsoft.VisualBasic; 

public partial class ReportGeneration : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     DataSet query = (DataSet)Session["myDataset"]; 
     GridView1.DataSource = query; 

     GridView1.DataBind(); 

    } 
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     DateTime dt; 
     long age; 
     Datefunctions3.DateClass d1 = new Datefunctions3.DateClass(); 
     //DateFunctions2.DateClass d1 = new DateFunctions2.DateClass(); 

     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      string s1 = e.Row.Cells[8].Text; 
      dt = Convert.ToDateTime(e.Row.Cells[8].Text); 
      // age = d1.DateDifference(da.Year, dt, DateTime.Now); 
      age = d1.DateDifference(DateInterval.year, d1, DateTime.Now); 


      e.Row.Cells[8].Text = age.ToString(); 
     } 
    } 
} 

這是我的代碼,它顯示了dateinterval不能夠解決的問題下錯誤添加我的Visual Basic函數的DLL文件到bin文件夾以及如何導入視覺基本功能到asp.net

+3

它顯示了什麼錯誤? – StriplingWarrior 2011-06-05 16:13:14

+0

另外,什麼版本的VB,或者你的意思是VB.NET? – 2011-06-05 17:04:04

回答

0

下面是一個擴展功能,這將使你的年齡W/O需要使用一個VB功能:

<Extension()> Function Age(dStart As DateTime) As Integer 
    Dim dNow As DateTime = DateTime.Now 
    Return dNow.Year - dStart.Year - If(dNow.Month > dStart.Month OrElse dNow.Month = dStart.Month AndAlso dNow.Day > dStart.Day,0,1) 
End Function 

用法:

age = d1.Age 

,或者,如果你不想使用擴展,直接使用它:

Dim dNow As DateTime = DateTime.Now 
    age = dNow.Year - d1.Year - If(dNow.Month > d1.Month OrElse dNow.Month = d1.Month AndAlso dNow.Day > d1.Day,0,1) 

我只注意到你的代碼是C#...你需要我的VB轉換爲C#