Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement