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

SAP Sybase SQL Anywhere 16.0 (中文) » UltraLite - .NET 编程 » UltraLite.NET 应用程序开发 » 使用 SQL 语句创建和修改数据

 

使用 SELECT 检索数据

执行 SELECT 语句可从 UltraLite 数据库检索信息并处理返回的结果集。

前提条件

执行此任务没有前提条件。

 任务
  1. 声明一个用于保存查询的 ULCommand 对象。

    ULCommand cmd;
  2. 将一条语句指派给该对象。

    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT MyColumn FROM MyTable";
  3. 执行语句。

    查询结果可以以其中一种对象类型的形式返回。在本示例中,使用了 ULDataReader 对象。

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

结果

SELECT 语句的结果中包含一个字符串,该字符串随后会输出到命令提示符处。