/* Poczenie w C# */

using System;
using System.Data.SqlClient;

class Programistw
{
   static void Main()
   {
        // Tre polece wydzielmy,
        // eby nie myliy si instrukcjami

      string strConnect = "Data Source=(local); Initial Catalog=master; Integrated Security=SSPI";
      string strCommand = "SELECT Name, database_id as ID FROM sys.databasesd";

      SqlDataReader rsMyRS = null;
      SqlConnection cnMyConn = new SqlConnection(strConnect);

      try{
           //Otwarcie poczenia
           // (pierwsze poczenie z serwerem baz danych)

         cnMyConn.Open();

           // Utwrzmy obiekt polecenia

         SqlCommand sqlMyCommand  = new SqlCommand(strCommand, cnMyConn);

           // Przygotujmy zestaw wyjciowy

         rsMyRS = sqlMyCommand.ExecuteReader();

           // Wyprowadmy wynik

         while (rsMyRS.Read())
         {
              // Wypiszmy pierwsz kolumn. Moemy rwnie
              // odnosi si do kolumn za pomoc ich nazwy

            Console.WriteLine (rsMyRS["Name"]);
         }
         finally
         {
              // Posprztajmy

            if (rsMyRS != null)
            {
               rsMyRS.Close();
            }
            if (cnMyConn != null)
            {
               cnMyConn.Close();
            }
         }
      }
   }



/* Poczenie w VB.NET */

Imports System
Imports System.Data
Imports System.Data.SqlClient

Module Program
   Sub Main()

        ' Tre polece wydzielmy,
        ' eby nie myliy si instrukcjami

      Dim strConnect As String = _
         "Data Source=(local); Initial Catalog=master; Integrated Security=SSPI";
      Dim strCommand As String = _
         "SELECT Name, database_id as ID FROM sys.databases" 

      Dim rsMyRS As SqlClient.SqlDataReader

      Dim cnMyConn As New SqlClient.SqlConnection(strConnect)

        ' Otwarcie poczenia
        ' (pierwsze poczenie z serwerem baz danych)
      cnMyConn.Open()

        ' Utwrzmy obiekt polecenia
      Dim sqlMyCommand As New SqlClient.SqlCommand(strCommand, cnMyConn)

        ' Przygotujmy zestaw wyjciowy
      rsMyRS = sqlMyCommand.ExecuteReader()

        ' Wyprowadmy wynik
      Do While rsMyRS.Read
           ' Wypiszmy pierwsz kolumn. Moemy rwnie 
           ' odnosi si do kolumn za pomoc ich nazwy
         Console.WriteLine(rsMyRS("Name"))
      Loop

        ' Posprztajmy
      rsMyRS.Close()
      cnMyConn.Close()

   End Sub
End Module

