"System.Indexoutofrangeexception" in my project c#

Asked

Viewed 10 times

0

In my financial software project I am trying to select in the database and have as a result the moves to be accounted for the balance, in my program I can already addlas in the database and all the other functions I wanted to try using the database, however when I try to do this query I get as a result that there is nothing in the index and if I change index goes telling me that there is no next and so it goes, these moves are already shown in a data grid view on the same screen so I know they are even in the database.

At the time I put this function in the same class as my login method, but I have tried it initially on the screen . Cs and in a separate class.

class Login
    {
        private static string usuario;
        private static string saldo;
        private static string id;

        public bool ValidarUsuario(string email, string senha)
        {
            ConexaoBD bd = new ConexaoBD();
            string sql = string.Format("select * from usuarios where email = '{0}' and senha = '{1}'", email, senha);
            DataTable dt = new DataTable();
            dt = bd.ConsultarDados(sql);

            if (dt.Rows.Count > 0)
            {
                usuario = dt.Rows[0]["usuario"].ToString();
                saldo = dt.Rows[0]["saldo"].ToString();
                id = dt.Rows[0]["id"].ToString();
                return true;
            }
            else
            {
                return false;
            }
        }
        public string UsuarioLogado()
        {
            return usuario;
        }
        public string SaldoUsuario()
        {
            return saldo;
        }
        public string idUsuario()
        {
            return id;
        }

From here

        public string Movimentacao(string tipo)
        {
            Login objLogin = new Login();
            string id = objLogin.idUsuario();
            string result;
            ConexaoBD bd = new ConexaoBD();
            string sql = string.Format("select * from movimentacoes where id = '{0}' and tipo = '{1}'", id, tipo);
            DataTable dt = new DataTable();
            dt = bd.ConsultarDados(sql);


            result = dt.Rows[0]["valor"].ToString();
            return result;

        }

hitherto

actually no longer know what to do, I did several searches and saw that it could be something in my connection class that could be closing after the first query, I tried to edit by removing the part of the code that closed the connection at the end of the query method but without success.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.