How to invert grid data

Asked

Viewed 69 times

1

inserir a descrição da imagem aquiI have a database with some tables to control software sales, and among these tables, I have software that contains the fields, beginning of the contract and end of the contract. Only when I select to appear like this ''21/12/2016', they appear like this in the grid ''12/21/2016' ?

private void MontarLista()
    {

        conexao.ConnectionString = strconexao;
        cmd.CommandText = "SELECT * FROM SOFTWARES";
        cmd.Connection = conexao;

        conexao.Open();
        cmd.CommandType = CommandType.Text;
        Dr = cmd.ExecuteReader();
        DtSoftwares.Clear();
        DtSoftwares.Load(Dr);
        dataGridView1.DataSource = DtSoftwares;
        conexao.Close();
        decimal soma = 0;


        foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
  • magnetun.mdf table software columns I need to start and end

  • work with sql server database, but am using local . mdf

  • Web Forms or Winds Forms?

2 answers

2

You can do

string.Format("{0:dd/MM/yyyy}", DateTime.ParseExact("12/21/2016", "MM/dd/yyyy"));

You replace "12/21/2016" with your string that is the date, or if you already have the Datetime object, just put it instead of the DateTime.ParseExact.

1

In the current way, I only see a simple way to resolve it. Format the date directly in select

cmd.CommandText = "SELECT FORMAT(INICIO, 'dd/MM/yyyy') AS INICIO, " + 
                        " OUTROS_CAMPOS FROM SOFTWARES";

This will make the column INICIO is formatted with the Brazilian standard.

  • cmd.Commandtext = "SELECT FORMAT(CAMPO_DE_DATA, 'dd/MM/yyyy') AS start, end FROM SOFTWARES";

  • It will look like this ! But what I put after the format in place of the field_de_data?

  • The name of the column

  • again ? I have put in the end start and finish , that are the two columns

  • Again what? I don’t understand what the problem is...

  • You can leave, I’m not knowing how to implement, thank you, I’ll see if I put a datepicker

  • 1

    @Rennanhanna no CAMPO_DE_DATA you must put it in the name of the column referring to the date. What is the name of the field referring to the start date? Is it even beginning? I mean the name that’s in your Software class.

  • I have two fields with date , start and end .

  • gave problem in my sum of columns value to display on a label. I will post the photo.

  • but I only put the starting field in place of the fields_data, I need to put end , as I would ?

Show 5 more comments

Browser other questions tagged

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