Use A Data Reader : SqlDataReader « Database ADO.net « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Database ADO.net » SqlDataReaderScreenshots 
Use A Data Reader


/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 * Version: 1
 */
using System;
using System.Data;
using System.Data.SqlClient;

namespace Client.Chapter_13___ADO.NET
{
    public class UsingADataReader
    {
        static void Main(string[] args)
        {
            SqlConnection MyConnection = new SqlConnection(@"Data Source=(local); Initial Catalog = CaseManager; Integrated Security=true");

            MyConnection.Open();

            SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo", MyConnection);
            SqlDataReader MyDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);

            while (MyDataReader.Read())
            {
                Console.WriteLine(MyDataReader[0" " + MyDataReader[1]);
            }

            MyConnection.Close();
        }
    }
}


           
       
Related examples in the same category
1.Execute multiple SELECT statements using a SqlCommand object and read the results using a SqlDataReader object
2.Get column index from SqlDataReader
3.use the GetOrdinal() from DataReader to get the numeric positions of a column
4.how to read column values as C# types using the Get* methods
5.read column values as Sql* types using the GetSql* methods
6.Read data from SqlDataReader
7.Reference data in SqlDataReader by column name
8.Use While loop to read query result data from SqlDataReader
9.Deal with Multiple Results
10.SqlDataReader Ordinal Indexer
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.