Read from SQL database

22/04/2015 17:18

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.SharePoint;

namespace SQLconnectionConApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "Data Source=serverName;Initial catalog=testDbName;Integrated Security=True;";
            cmdText = "SELECT Code, Description FROM [Currency]";
           
            List<string> list2 = new List<string>();

            using (SqlConnection connection = new SqlConnection(connectionString))
   
               {
                   SqlCommand command = new SqlCommand(cmdText, connection);
                   connection.Open();
                   try
                   {
                       SqlDataReader reader = command.ExecuteReader();
                       while (reader.Read())
                       {
                           list2.Add(reader[0].ToString());
                           Console.WriteLine(reader[0].ToString());
                       }
                   }
                   catch (Exception ex)
                   {
                       Console.WriteLine(ex.ToString());
                   }
                   finally
                   {
                       Console.ReadLine();
                   }
               }
       
        }
    }
}