Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Data.SqlClient;
  3.  
  4. namespace LocalDBTest
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\TestDB; Initial Catalog=APP_DATA; Integrated Security=false;user id=" + "Admin" + ";password=" + "ironrhino420");
  11.             SqlCommand command = new SqlCommand("Select * From Test", conn);
  12.             conn.Open();
  13.             SqlDataReader reader = command.ExecuteReader();
  14.             try
  15.             {
  16.                 while (reader.Read())
  17.                 {
  18.                     Console.WriteLine("Successful Connection");
  19.                     Console.WriteLine(String.Format("{0}, {1}",
  20.                     reader["Column1"], reader["Column2"]));
  21.                 }
  22.             }
  23.             finally
  24.             {      
  25.                 reader.Close();
  26.             }
  27.            
  28.             Console.WriteLine("Hello World!");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement