i useSELECT time from ***
and in c#, my current time is:Datetime.now
when i was usingtimespan ts = cmd.ExecuteScalar() - DateTime.Now;
but when i use to print out cmd.ExecuteScalar().getType().ToString(); and DateTime.Now.getType().ToString(); they both returns system.datetime.
how can i get the timespan from the one i retrive from sql server and another from c#. system.datetime.now?
In your case, since you are querying for DateTime from Sql, the inherrent type returned is a DateTime. However the method ExecuteScalar is written to support returning of all possible types and hence uses the base of all types, i.e. System.Object.
When you execute the method, the actual type returned is DateTime. Invoking GetType, thus internally is invoked on DateTime, since that is the contained type at that moment and hence returns System.DateTime. If you had queried for an int or a string, you would have got System.Int32 or System.String
To be able to use the value returned by ExecuteScalar as right type, you will have to do a type casting