Public paste
Undefined
By: Guest | Date: Nov 17 2009 14:47 | Format: None | Expires: never | Size: 1.51 KB | Hits: 480

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7.  
  8. namespace Boek_Hoofdstuk_28
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.           SqlConnection thisConnection = new SqlConnection
  15.          
  16.           (
  17.          
  18.           @"Data Source=.SQLEXPRESS;" +
  19.           @"AttachDbFilename=’C:Documents and SettingsJeroenYBureaubladNortwind database Voor SQLbiblio_2000.mdb’;" +
  20.           @"Integrated Security=True;Connect Timeout=30;User Instance=true"
  21.           );
  22.              
  23.    // Open connection
  24.    thisConnection.Open();
  25.              
  26.    // Create command for this connection
  27.    SqlCommand thisCommand = thisConnection.CreateCommand();
  28.              
  29.    // Specify SQL query for this command
  30.    thisCommand.CommandText =
  31.         "SELECT CustomerID, CompanyName from Customers";
  32.              
  33.    // Execute DataReader for specified command
  34.    SqlDataReader thisReader = thisCommand.ExecuteReader();
  35.              
  36.    // While there are rows to read
  37.    while (thisReader.Read())
  38.    {
  39.       // Output ID and name columns
  40.       Console.WriteLine("t{0}t{1}",
  41.       thisReader["CustomerID"], thisReader["CompanyName"]);
  42.    }
  43.              
  44.    // Close reader
  45.    thisReader.Close();
  46.              
  47.    // Close connection
  48.    thisConnection.Close();
  49.              
  50.    Console.Write("Program finished, press Enter/Return to continue:");
  51.    Console.ReadLine();
  52.         }
  53.     }
  54. }
Latest pastes
5 minutes ago
2 hours ago
6 days ago
17 days ago
23 days ago