Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compare timestamp fields?

Status
Not open for further replies.

joggi

Programmer
Nov 8, 2006
44
YU
In my SQLServer database I have Timestamp field. I want to compare these fields like this:

If ds1.Rows(0).Item("Timestamp") = ds.Rows(0).Item("Timestamp") Then
.....
end if

I got error :

"Operater '=' is not defined for type 'Byte()'"

How to compare these fields?
 
Try using the DateTime.Compare method:


As a side note, I notice that you haven't yet responded to any of the questions you have asked to either thanks the user for their help, nor to say whether their solution worked. I suggest you read the FAQ in my signature (especially items #15 and #16).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Sorry, I didn't want to be unpolite.
When I post my question I always say "Thanks in advance".

Timestamp field is binary field, it's not datetime field. I need VB.NET code to compare those fields.

You can read something about this here:


Thanks everybody for helping me, I am new with .NET and I am in a hurry to finish my project.
 
You can use the CDate() function to convert your item before passing it to the DateTime.Compare method.

Sorry, I didn't want to be unpolite.
When I post my question I always say "Thanks in advance".
I didn't mean to imply you were impolite, I just meant that it is forum etiquette to reply to any help you receive (or to click on the link underneath each post which will also thank the relevant user) to directly say "Thank You" and to inform the poster whether their solution worked or not.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you, but this doesn't work.
Timestamp is special type, it is not datetime, it is binary field. You can't see that field as datetime.
 
Can you use the ToString method on the "ds1.Rows(0).Item("Timestamp")" Item? What does that return?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
No, I can't. It returns empty string.
When I bind dataset with that timestamp field to gridview, field Timestamp is not visible, because is binary.
It is specific datatype, you can't see the value of this field and it is used for concurrency matter. When you update row in the database this field is updated too, it is unique, so comparing this fields you can check if somebody changed that row,because you have disconnected dataset.
 
Maybe the "System.Data.SqlDbType.Timestamp.CompareTo()" method could be used then. It accepts a parameter which will compare the object against another timestamp and return an Integer based on whether it matches or not.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top