开发者

how to import visual basic function into asp.net

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();
        }
    }
}

This is my code it shows error under the dateinterval not able to solve the problem have added a dll file of my visual basic function into the BIN folder as well


Here's an extension function that will give you the age w/o needing to use a VB function:

<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

usage:

age = d1.Age

or, if you don't want to use an extension, use it directly:

  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)

I just noticed that your code is C#... you'll need to convert my vb to C#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜