Beispiel #1
0
        public List <Sucursales> findAll()
        {
            List <Sucursales> lista            = new List <Sucursales>();
            Sucursales        obj              = new Sucursales();
            string            queryString      = "select s.CodigoSucursales,s.Nombre,s.Direccion,s.FechaRegistro,(select b.Nombre from Banco b where b.CodigoBanco = s.CodigoBanco) as Banco from Sucursales s";
            string            connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = " + AppDomain.CurrentDomain.BaseDirectory + "App_Data\\Bancos.mdf" + ";Integrated Security = True;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        obj = new Sucursales();
                        obj.CodigoSucursales = (int)reader["CodigoSucursales"];
                        obj.Nombre           = (string)reader["Nombre"];
                        obj.Direccion        = (string)reader["Direccion"];
                        obj.FechaRegistro    = (DateTime)reader["FechaRegistro"];
                        obj.Banco            = (string)reader["Banco"];
                        lista.Add(obj);
                    }
                }
                finally
                {
                    reader.Close();
                }
                return(lista);
            }
        }
Beispiel #2
0
        public bool create(Sucursales oSucursales)
        {
            try
            {
                string queryString      = "insert into Sucursales (Nombre,Direccion,FechaRegistro,CodigoBanco) values('" + oSucursales.Nombre + "','" + oSucursales.Direccion + "',GETDATE()," + oSucursales.CodBanco + ")";
                string connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = " + AppDomain.CurrentDomain.BaseDirectory + "App_Data\\Bancos.mdf" + ";Integrated Security = True;";

                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand(queryString, connection);
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }