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

SQL Anywhere 10.0.1 » UltraLite - .NET Programming » Understanding UltraLite.NET Development » Accessing and manipulating data using SQL

Data manipulation: INSERT, UPDATE, and DELETE Next Page

Data retrieval: SELECT

The SELECT statement allows you to retrieve information from the database. This section describes how to execute a SELECT statement and how to handle the result set it returns.

To execute a SELECT statement
  1. Declare a ULCommand object, which holds the query.

    ULCommand cmd;
  2. Assign a statement to the object.

    cmd = conn.CreateCommand();
    cmd.Command =
       "SELECT MyColumn FROM MyTable";
  3. Execute the statement.

    Query results can be returned as one of several types of objects. In this example, a ULDataReader object is used. In the following code, the result of the SELECT statement contains a string, which is output to the console window.

    ULDataReader customerNames = prepStmt.ExecuteReader();
    int fc = customerNames.GetFieldCount();
    while( customerNames.MoveNext() ) {
      for ( int i = 0; 
        i < fc; 
        i++ ) {
        customerNames.GetString( i ) + " " );