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文件夹中
答案 0 :(得分:0)
这是一个扩展函数,它将为您提供不需要使用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#