Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct NomAp
- {
- public string Nombre;
- public string Apellido;
- }
- public Dictionary<NomAp, string> dicSelect(string connectionString)
- {
- Dictionary<NomAp, string> dicResult = new Dictionary<NomAp, string>();
- using (SqlConnection conn = new SqlConnection(connectionString))
- {
- using (SqlCommand cmd = new SqlCommand("spSelect", conn) { CommandType = CommandType.StoredProcedure })
- {
- conn.Open();
- using(SqlDataReader reader = cmd.ExecuteReader())
- {
- while(reader.Read())
- {
- string strNombre = reader.GetString(0);
- string strApellido = reader.GetString(1);
- string strMail = reader.GetString(2);
- NomAp pair = new NomAp { Nombre = strNombre, Apellido = strApellido };
- dicResult.Add(pair, strMail);
- }
- }
- }
- }
- return dicResult;
- }
- static void Main(string[] args)
- {
- clsSQL sql = new clsSQL();
- string strEstado = "";
- try
- {
- strEstado = sql.isConnected(sql.strConn()) ? "CONECTADO" : "NO CONECTADO";
- Console.WriteLine("Estado de la conexión: {0}\n", strEstado);
- foreach (KeyValuePair<clsSQL.NomAp, string> kp in sql.dicSelect(sql.strConn()))
- {
- Console.WriteLine("Nombre: {0} {1} Mail: {2}", kp.Key.Nombre, kp.Key.Apellido, kp.Value);
- }
- }
- catch(SqlException ex)
- {
- Console.WriteLine("SQL Server Error: {0}", ex.Message);
- }
- Console.ReadLine();
- }
- CREATE PROC spSelect
- AS
- BEGIN
- SELECT TOP 5 p1.FirstName, p1.LastName, p2.EMailAddress
- FROM Person.Person p1, Person.EmailAddress p2
- WHERE p2.BusinessEntityID = p1.BusinessEntityID
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement