SqlDataReader.Read メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataReader.Read メソッドの意味・解説 

SqlDataReader.Read メソッド

SqlDataReader を次のレコード進めます

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

解説解説

SqlDataReader既定位置は、先頭レコードの前です。そのため、データへのアクセス開始するには、Read呼び出す必要があります

関連付けられた SqlConnection で開くことのできる SqlDataReader は、一度1 つだけです。データ リーダー閉じ前に別のデータ リーダーを開くことはできません。同様にSqlDataReader使用中は、関連付けられた SqlConnection は、そのデータ リーダーによって使用されるため、Close呼び出されるまではビジー状態になります

使用例使用例

SqlConnection、SqlCommand、および SqlDataReader作成する例を次に示します。この例では、データ読み取りコンソール ウィンドウ出力します次にSqlDataReader閉じますSqlConnection は、using コード ブロック末尾自動的に閉じられます。

Private Sub ReadOrderData(ByVal
 connectionString As String)
    Dim queryString As String
 = _
        "SELECT OrderID, CustomerID FROM dbo.Orders;"

    Using connection As New SqlConnection(connectionString)
        Dim command As New
 SqlCommand(queryString, connection)
        connection.Open()

        Dim reader As SqlDataReader = command.ExecuteReader()

        ' Call Read before accessing data.
        While reader.Read()
            Console.WriteLine(String.Format("{0},
 {1}", _
                reader(0), reader(1)))
        End While

        ' Call Close when done reading.
        reader.Close()
    End Using
End Sub
private static void ReadOrderData(string
 connectionString)
{
    string queryString =
        "SELECT OrderID, CustomerID FROM dbo.Orders;";

    using (SqlConnection connection =
               new SqlConnection(connectionString))
    {
        SqlCommand command =
            new SqlCommand(queryString, connection);
        connection.Open();

        SqlDataReader reader = command.ExecuteReader();

        // Call Read before accessing data.
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }

        // Call Close when done reading.
        reader.Close();
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からSqlDataReader.Read メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSqlDataReader.Read メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSqlDataReader.Read メソッドを検索

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

辞書ショートカット

すべての辞書の索引

SqlDataReader.Read メソッドのお隣キーワード
検索ランキング

   

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



SqlDataReader.Read メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS