Contents Index Handling BLOBs Using stored procedures

ASA Programming Guide
  Developing Applications with the .NET Data Provider
    Accessing and manipulating data

Obtaining time values


The .NET Framework does not have a Time structure. If you want to fetch time values from Adaptive Server 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.

    AsaConnection conn = new AsaConnection(
        "Data Source=dsn-time-test;uid=dba;pwd=sql" );
  2. Open the connection.

    conn.Open();
  3. Add a Command object to define and execute a SQL statement.

    AsaCommand cmd = new AsaCommand(
        "SELECT id, time_col FROM time_test", conn )
  4. Call the ExecuteReader method to return the DataReader object.

    AsaDataReader 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.

    reader.Close();
    conn.Close();

Contents Index Handling BLOBs Using stored procedures