Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere .NET Data Provider » Accessing and manipulating data

Handling BLOBs Next Page

Obtaining time values

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
  1. Declare and initialize a connection object.

    SAConnection conn = new SAConnection(
        "Data Source=dsn-time-test;UID=DBA;PWD=sql" );
  2. Open the connection.

  3. Add a Command object to define and execute a SQL statement.

    SACommand cmd = new SACommand(
        "SELECT ID, time_col FROM time_test", conn )
  4. 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();
  5. Close the DataReader and Connection objects.