DataTableReader.HasRows プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataTableReader.HasRows プロパティの意味・解説 

DataTableReader.HasRows プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

DataTableReader に 1 行以上の行が格納されているかどうかを示す値を取得します

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Dim instance As DataTableReader
Dim value As Boolean

value = instance.HasRows
public override bool HasRows { get;
 }
/** @property */
public boolean get_HasRows ()

プロパティ
1 行以上の行が DataTableReader含まれている場合trueそれ以外場合false

例外例外
例外種類条件

InvalidOperationException

閉じられDataTableReader に関する情報取得しようとしました

解説解説
使用例使用例

2 つの DataTable インスタンスデータ格納する例を次に示します。1 番目の DataTable には行が 1 つ含まれ2 番目には行が含まれていません。この例では 2 つDataTable を含む DataTableReader作成し、PrintData メソッド呼び出してそれぞれの内容表示します。PrintData を呼び出す前にそれぞれの HasRows プロパティの値を確認します

Private Sub TestHasRows()
   'Retrieve one row from the Store table:
   Dim customerTable As DataTable = GetCustomers()
   Dim productsTable As DataTable = GetProducts()

   Using reader As New DataTableReader( _
      New DataTable() {customerTable, productsTable})

      Do
         If reader.HasRows Then
            PrintData(reader)
         End If
      Loop While reader.NextResult()
   End Using

   Console.WriteLine("Press Enter to finish.")
   Console.ReadLine()
End Sub

Private Sub PrintData( _
   ByVal reader As DataTableReader)

   ' Loop through all the rows in the DataTableReader.
   Do While reader.Read()
      For i As Integer =
 0 To reader.FieldCount - 1
         Console.Write("{0} ", reader(i))
      Next
      Console.WriteLine()
   Loop
End Sub
Private Function GetCustomers() As
 DataTable
   ' Create sample Customers table, in order
   ' to demonstrate the behavior of the DataTableReader.
   Dim table As New DataTable

   ' Create two columns, ID and Name.
   Dim idColumn As DataColumn = table.Columns.Add("ID",
 GetType(Integer))
   table.Columns.Add("Name", GetType(String))

   ' Set the ID column as the primary key column.
   table.PrimaryKey = New DataColumn() {idColumn}

   table.Rows.Add(New Object() {1, "Mary"})
   Return table
End Function

Private Function GetProducts() As
 DataTable
   ' Create sample Products table, in order
   ' to demonstrate the behavior of the DataTableReader.
   Dim table As New DataTable

   ' Create two columns, ID and Name.
   Dim idColumn As DataColumn = table.Columns.Add("ID",
 GetType(Integer))
   table.Columns.Add("Name", GetType(String))

   ' Set the ID column as the primary key column.
   table.PrimaryKey = New DataColumn() {idColumn}

   Return table
End Function
private static void TestHasRows()
{
    DataTable customerTable = GetCustomers();
    DataTable productTable = GetProducts();

    using (DataTableReader reader = new DataTableReader(
               new DataTable[] { customerTable, productTable }))
    {
        do
        {
            if (reader.HasRows)
            {
                PrintData(reader);
            }
        } while (reader.NextResult());
    }

    Console.WriteLine("Press Enter to finish.");
    Console.ReadLine();
}

private static void PrintData(DataTableReader
 reader)
{
    // Loop through all the rows in the DataTableReader
    while (reader.Read())
    {
        for (int i = 0; i < reader.FieldCount;
 i++)
        {
            Console.Write(reader[i] + " ");
        }
        Console.WriteLine();
    }
}

private static DataTable GetCustomers()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();
    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string ));
    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 1, "Mary" });
    return table;
}

private static DataTable GetProducts()
{
    // Create sample Products table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();

    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string ));
  
    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };
    return table;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataTableReader クラス
DataTableReader メンバ
System.Data 名前空間
NextResult
Read



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DataTableReader.HasRows プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataTableReader.HasRows プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS