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

SQL Anywhere 12.0.0 (Français) » UltraLite - .NET Programming » Understanding UltraLite.NET development » Accessing and manipulating data using SQL


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 command prompt.

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