Created
January 8, 2017 23:21
-
-
Save renatogroffe/cdb0fe0721f5421542881e01eb7b18d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.SqlClient; | |
namespace TesteNETCoreSQL | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine("Relação de países e códigos telefônicos\n"); | |
string connectionString = | |
"Data Source=localhost;" + | |
"Initial Catalog=ExemploPaises;" + | |
"User ID=SA;" + | |
"Password=UbuntuSQL2016;"; | |
using (SqlConnection conexao = | |
new SqlConnection(connectionString)) | |
{ | |
SqlCommand cmd = conexao.CreateCommand(); | |
cmd.CommandText = | |
"SELECT Sigla, NomePais, CodigoTelefonico " + | |
"FROM dbo.Paises " + | |
"ORDER BY Sigla"; | |
conexao.Open(); | |
SqlDataReader reader = cmd.ExecuteReader(); | |
while (reader.Read()) | |
{ | |
Console.WriteLine( | |
$"{reader["CodigoTelefonico"]} {reader["NomePais"]} ({reader["Sigla"]})"); | |
} | |
conexao.Close(); | |
} | |
Console.WriteLine("\nTérmino da aplicação TesteNETCoreSQL"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment