The .NET Framework does not have a Time structure. If you want to fetch time values from SQL Anywhere, you must use the GetTimeSpan method. Using this method returns the data as a .NET Framework TimeSpan object.
For more information about the GetTimeSpan method, see GetTimeSpan method.
To convert a time value using the GetTimeSpan method
Declare and initialize a connection object.
SAConnection conn = new SAConnection( "Data Source=dsn-time-test;UID=DBA;PWD=sql" ); |
Open the connection.
conn.Open(); |
Add a Command object to define and execute a SQL statement.
SACommand cmd = new SACommand( "SELECT ID, time_col FROM time_test", conn ) |
Call the ExecuteReader method to return the DataReader object.
SADataReader reader = cmd.ExecuteReader(); |
The following code uses the GetTimeSpan method to return the time as TimeSpan.
while ( reader.Read() ) { int ID = reader.GetInt32(); TimeSpan time = reader.GetTimeSpan(); } |
Close the DataReader and Connection objects.
reader.Close(); conn.Close(); |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |