Guest User

Untitled

a guest
Dec 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6.  
  7. namespace _4004Iteration1{
  8.     class Program{
  9.  
  10.         static void Main(string[] args){
  11.             SqlConnection connection = new SqlConnection("user id=L;" +
  12.                                        "server=localhost;" +
  13.                                        "Trusted_Connection=yes;" +
  14.                                        "database=HospitalDB; " +
  15.                                        "connection timeout=30");
  16.  
  17.             try{
  18.                 connection.Open();
  19.             }
  20.             catch (Exception e){
  21.                 Console.WriteLine(e.ToString());
  22.             }
  23.  
  24.             SqlCommand insert = new SqlCommand("INSERT INTO test (numbers) values (105)", connection);
  25.             insert.ExecuteNonQuery();
  26.  
  27.             try{
  28.                 SqlDataReader myReader = null;
  29.                 SqlCommand select = new SqlCommand("select * from test", connection);
  30.                 myReader = select.ExecuteReader();
  31.                 while (myReader.Read()){
  32.                     Console.WriteLine(myReader["numbers"].ToString());
  33.                 }
  34.             }
  35.             catch (Exception e){
  36.                 Console.WriteLine(e.ToString());
  37.             }
  38.  
  39.             System.Console.ReadLine();
  40.  
  41.         }
  42.     }
  43. }
Add Comment
Please, Sign In to add comment