Created
March 30, 2018 19:34
-
-
Save Fhernd/3cc91044b158314b57ca8934cb2824e1 to your computer and use it in GitHub Desktop.
Lectura de datos de una consulta SQL. OrtizOL.
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; | |
using System.Data.SqlClient; | |
namespace R907LectorDatosConsultaSql | |
{ | |
class R907Programa | |
{ | |
static void Main(string[] args) | |
{ | |
using (SqlConnection conexion = new SqlConnection()) | |
{ | |
conexion.ConnectionString = @"Data source =.\SQLEXPRESS; Initial catalog = Northwind;Integrated Security=SSPI"; | |
using (SqlCommand comando = conexion.CreateCommand()) | |
{ | |
comando.CommandType = CommandType.Text; | |
comando.CommandText = | |
"SELECT BirthDate, FirstName, LastName FROM Employees ORDER BY BirthDate;SELECT * FROM Employees"; | |
conexion.Open(); | |
using (SqlDataReader lectorDatos = comando.ExecuteReader()) | |
{ | |
Console.WriteLine("Cumpleaños de los empleados por edad:"); | |
while (lectorDatos.Read()) | |
{ | |
Console.WriteLine("\t{0,18:D} - {1} {2}", | |
lectorDatos.GetDateTime(0), | |
lectorDatos["FirstName"], | |
lectorDatos[2]); | |
} | |
Console.WriteLine("\nMetados de la tabla `Employees`:"); | |
for (int campo = 0; campo < lectorDatos.FieldCount; campo++) | |
{ | |
Console.WriteLine("\tNombre Columna: {0} - Tipo: {1}", | |
lectorDatos.GetName(campo), | |
lectorDatos.GetDataTypeName(campo)); | |
} | |
} | |
} | |
} | |
Console.WriteLine("\n\nPresione Enter para finalizar..."); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment