Exemple #1
0
        public List <Bancos> findAll()
        {
            List <Bancos> lista            = new List <Bancos>();
            Bancos        obj              = new Bancos();
            string        queryString      = "select * from Banco";
            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);
                //command.Parameters.AddWithValue("@tPatSName", "Your-Parm-Value");
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        obj               = new Bancos();
                        obj.CodigoBanco   = (int)reader["CodigoBanco"];
                        obj.Nombre        = (string)reader["Nombre"];
                        obj.Direccion     = (string)reader["Direccion"];
                        obj.FechaRegistro = (DateTime)reader["FechaRegistro"];
                        lista.Add(obj);
                        //Console.WriteLine(String.Format("{0}, {1}",
                        //reader["tPatCulIntPatIDPk"], reader["tPatSFirstname"]));
                    }
                }
                finally
                {
                    // Always call Close when done reading.
                    reader.Close();
                }
                return(lista);
            }
        }
Exemple #2
0
        public Bancos find(string CodigoBanco)
        {
            Bancos obj              = new Bancos();
            string queryString      = "select * from Banco where CodigoBanco = " + CodigoBanco;
            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);
                //command.Parameters.AddWithValue("@tPatSName", "Your-Parm-Value");
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        obj               = new Bancos();
                        obj.CodigoBanco   = (int)reader["CodigoBanco"];
                        obj.Nombre        = (string)reader["Nombre"];
                        obj.Direccion     = (string)reader["Direccion"];
                        obj.FechaRegistro = (DateTime)reader["FechaRegistro"];
                    }
                }
                finally
                {
                    reader.Close();
                }
                return(obj);
            }
        }
Exemple #3
0
        public bool create(Bancos oBancos)
        {
            try
            {
                string queryString      = "insert into Banco (Nombre,Direccion,FechaRegistro) values('" + oBancos.Nombre + "','" + oBancos.Direccion + "',GETDATE())";
                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);
            }
        }
Exemple #4
0
        public bool edit(Bancos oBancos)
        {
            try
            {
                string queryString      = "update Banco set Nombre ='" + oBancos.Nombre + "',Direccion ='" + oBancos.Direccion + "' where CodigoBanco = " + oBancos.CodigoBanco;
                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);
            }
        }