خانه > مقالات > ado.net > طریقه استفاده از SqlDataReader در DOT NET
منو
کاربری
سلام مهمان
IP: 38.107.179.224

نام کاربری
رمز عبور
ثبت نام
 رمز عبور فراموش شده
تاپ لینک
اشتراک گوگل
طریقه استفاده از SqlDataReader در DOT NET
Date 07/03/2009 16:45 Author admin
RSS

SqlDataReader can be used if you want to keep an open connection to the database and use the rows as they come to you (forward only stream of data). 
When you use SqlHelper.ExecuteDataSet, what happens is it serializes the data to XML and returns it to you at the end of
the GET operation.  However, with SqlDataReader, you get the rows as they come, which can be handy if there is a lot of
rows (say, millions), or if you have some sort of parallel processing you want to do while the data is still coming.  

Here is an example of how to use SqlDataReader.  Take a look below for an example, uses both SqlCommand and then
the
Microsoft Application Blocks version

Download the source code for the below example

While Microsoft provides you with the Microsoft ApplicationBlock class to make your database-driven application development easier, occasionally, you may have to use .NET’s built-in SqlReader class to connect to a database. 

Using SqlReader is quite simple–you feed it a connection string and a query, then pull fields and use readerInstance.Read() to advance row-by-row. 

First, set up your application with the appropriate settings, including the connection to the database: 


string connectionString = "...";

        string query = "..."; 

        SqlConnection conn = new SqlConnection(connectionString); 

        try

        {

            conn.Open();

        }

        catch (Exception ex)

        {

            MessageBox.Show("Couldn't open a connection to the database.  The exception is " + ex.ToString());

            conn.Close();

        }
Tags -   
نظری وجود ندارد
نام
ایمیل
نظر
mail:info@taymaz.ir    tel: 0914 401 5436 --- 0914 103 6932 --- 0935 428 0101
script & code