tags:

views:

1085

answers:

3

Hi,

I wanna get the Timedate value from another page using request.querystring and then use it an query to compare and pull up the matching datas. The function for the query in linq is:

   protected void User_Querytime()
    {
    DataClasses2DataContext dc1 = new DataClasses2DataContext();
    String  Data = Request.QueryString["TimeOfMessage"];

                var query7 = from u in dc1.syncback_logs
                             where u.TimeOfMessage = Data
                             orderby u.TimeOfMessage descending
                             select u;
                GridView1.DataSource = query7;
                GridView1.DataBind();
    }

Here the "Request.QueryString["TimeOfMessage"]" which i get is DateTime (ex:8/25/2008 9:07:19 AM). I wanted to compare it against the "u.TimeOfMessage" in database and pull up the matching records.

When I use todatetime function to convert from string to datetime ,the value returned is bool and hence not able to compare it against the "Timeofmessage" which is datetime format in database. Can anyone help me in this?

+1  A: 

Do you mean Convert.ToDateTime? This returns DateTime (not bool). Do you mean DateTime.TryParse? Simply use any of:

DateTime when = DateTime.Parse(data);
DateTime when = DateTime.ParseExact(data);
DateTime when = Convert.ToDateTime(data);

Then use "when" in the query. I'm not sure the purpose of ordering by it if you know they are all equal, though... did I miss something?

If the issue is that you want only the time part (not the date part), could you clarify that?

Marc Gravell
A: 

Time and Date is a single feild in the database. I get it from another page (say I get x) and compare the x against all the Timeanddate in database and display in grid the timeanddate which matches x.

I am not able to convert the request.querystring which is a string to datetime and compare it in database

is the explanation clear?

A: 

Hi,

the TryParse indeed results a bool (as the success of the parsing):

Dim DateText = Request.QueryString("date")
Dim MyDate As DateTime = Nothing
If DateTime.TryParse(DateText, MyDate) Then
  '--Date was passed correctly
End If

regards Christoph

Christoph