Doubts about the datagridview

Asked

Viewed 233 times

1

Hello I have some questions about the datagridview of visual studio, I would like to know how I can change the values of the columns that appear to Foreign key of sql server by the value of the table that is referenced the primary key, and also wanted to know how I can add up the total values shown

inserir a descrição da imagem aqui

Code that I’m trying to use, but it’s an error because I can’t put a String in the columns because they were set to int and I can’t change it

 public static DataTable fillDataTable(string query)
        {
            using (OdbcConnection conexao = Conexao.CreateConnection())
            {
                OdbcCommand comando = new OdbcCommand(query, conexao);
                conexao.Open();
                DataTable dt = new DataTable();

                try
                {
                    dt.Load(comando.ExecuteReader());


                  for(int i = 0; i < dt.Rows.Count; i++)
                    {
                        String query2 = "SELECT * FROM tbTipoConta WHERE idTipoConta = "+dt.Rows[i][1];
                        List<TipoDeConta> t = CRUD_TipoDeConta.consultaTipoConta(query2);
                        dt.Rows[i][1]= t[0].nomeTipoDeConta;
                    }
                }
                catch (Exception e)
                {

                    throw;
                }

                return dt;
            }
        }
  • Your question is very confusing. You want to change the value of columns idGasto and idTipoConta, that?

  • i wish that instead of appearing the id number in the fields , appeared the name to which this id is related, I will put a code in the question, to better understand what I want, but this code is giving error because I am trying to put a String where has an int, and I’m not getting to change the kind of value

1 answer

1


Browser other questions tagged

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