Obtaining time values

The .NET Framework does not have a Time structure. If you want to fetch time values from Adaptive Server, you must use the GetDateTime() method. Using this method returns the data as a .NET Framework DateTime object.

StepsConverting a time value using the GetDateTime method

  1. Declare and initialize a connection object:

    For C#:

    AseConnection conn = new AseConnection(
       c_connStr );
    

    For Visual Basic .NET:

    Dim conn As New AseConnection( _
       c_connStr )
    
  2. Open the connection:

    For C#:

    conn.Open();
    

    For Visual Basic .NET:

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

    For C#:

    AseCommand cmd = new AseCommand( 
       "SELECT title_id, title, pubdate FROM titles", 
       conn );
    

    For Visual Basic .NET:

    Dim cmd As New AseCommand( _
       "SELECT title_id, title, pubdate FROM titles", _
       conn)
    
  4. Call the ExecuteReader method to return the DataReader object:

    For C#:

    AseDataReader reader = cmd.ExecuteReader();
    

    For Visual Basic .NET:

    Dim reader As AseDataReader = cmd.ExecuteReader()
    

    The following code uses the GetDateTime method to return the DateTime value:

    For C#:

    while ( reader.Read() )
    { 
       String tid = reader.GetString(0);
       String title = reader.GetString(1);
       DateTime time = reader.GetDateTime(2);
       // do something with the data
    }
    

    For Visual Basic .NET:

    While reader.Read()
       Dim tid As String = reader.GetString(0)
       Dim title As String = reader.GetString(1)
       Dim time As DateTime = reader.GetDateTime(2)
       ' do something with the data....
    End While
    
  5. Close the DataReader and Connection objects:

    For C#:

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

    For Visual Basic .NET:

    reader.Close()
    conn.Close()