sql database in c#

how to read line by line from database

Page 1 of 1

1 Replies - 1168 Views - Last Post: 24 August 2009 - 04:40 AM Rate Topic: -----

#1 dharshinfotech  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-August 09

sql database in c#

Post icon  Posted 24 August 2009 - 03:31 AM

how to read line by line from database
Is This A Good Question/Topic? 0
  • +

Replies To: sql database in c#

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: sql database in c#

Posted 24 August 2009 - 04:40 AM

View Postdharshinfotech, on 24 Aug, 2009 - 06:31 AM, said:

how to read line by line from database


for me, it's easiest to use the SqlConnection, SqlCommand, and SqlDataReader classes.

using (SqlConnection conn = new SqlConnection(yourConnectionString))
{
     using (SqlCommand cmd = new SqlCommand())
     {
          // your command code(connection, query, etc.)

          using (SqlDataReader dr = cmd.ExecuteReader())
          {
               while (dr.Read())
               {
                   //process the current data
                   // if the first column is a string type
                   string someData = dr.GetString(0);
               }
          }

     }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1