accessing a dataset

Jellybaby

Newcomer
Joined
Feb 12, 2004
Messages
14
Hi

Does anyone know how to compare a date in a dataset to todays date?

My code is;
myDate=DateTime.Now()
Dim MyConnection As SqlConnection = New SqlConnection("server=(local); trusted_connection=true; database=ExamResults")
MyConnection.Open()

Dim MyDataCommand As SqlDataAdapter
Dim DS
DS = New DataSet()

'CHECK EXPIRY DATE
MyDataCommand = New SqlDataAdapter("SELECT * FROM tblExpiryDate WHERE (ExpYear = ' " & myYear & "')", MyConnection)
MyDataCommand.Fill(DS, "tblExpiryDate")
rsExpiry.DataSource = DS.Tables("tblExpiryDate").DefaultView
rsExpiry.DataBind()

if (DataBinder.Eval(Container.DataItem, "ExpDate") < myDate)

Any help would really be appreciated
Thanks
 
I snipped code from you...

"if (DataBinder.Eval(Container.DataItem, "ExpDate") < myDate)"

Where are you using the DataBinder? In the "HTML" File (in c# this is the .aspx file -> you are using vb and i don't know the name...)

First of all, when you are using the DataBinder in the "HTML" file, you can't do any "if" commands with the DataBinder!!!

Therefore you have to do this:

codebehind:
Code:
public string MyFunction(object o)
{
  return ((DateTime)o).ToShortDateString();
}

html:
Code:
<%# MyFunction(DataBinder.Eval(Container.DataItem, "ExpDate")) %>

When you use the DataBinder in your code-behind you only have to typecast...


if ((DateTime)DataBinder.Eval(Container.DataItem, "ExpDate") < myDate)


Regards, Stefan
 
Back
Top