insert and update date values in the DB using a makedtextbox C #

0
Hello, while I was developing a system to manage the records in the DB in error it is happening that when inserting the values the date records are empty and when trying to update the listing of information it gives an error that says that it can not format the values in DateTime.

if (status == "novo")
                {  
                    Conexao.cmdMySql.CommandText = "INSERT INTO eventos (id_event,nome_event,descricao_event,local_event,data_event,latitude_event,longitude_event) VALUES('" + codigo_tb.Text + "','" + nome_tb.Text + "','" + descricao_tb.Text + "','" + local_tb.Text + "','" + maskedTextBox1.Text + "','" + latitude_tb.Text + "','" + longitude_tb.Text + "')";
                    Conexao.cmdMySql.ExecuteNonQuery();
                    MessageBox.Show("Registro salvo com sucesso", "Salvar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (status == "editar")
                {
                    DateTime data_datetime = DateTime.Now;
                    string format = "yyyy-MM-dd";
                    Conexao.cmdMySql.CommandText = "UPDATE eventos SET id_event='" + codigo_tb.Text + "',nome_event='" + nome_tb.Text + "',descricao_event='" + descricao_tb.Text + "',local_event='" + local_tb.Text + "',data_event='" + data_datetime.ToString(format) + "',latitude_event='" + latitude_tb.Text + "',longitude_event='" + longitude_tb.Text + "' WHERE id_event='" + event_lstv.Items[event_lstv.FocusedItem.Index].Text + "'";
                    Conexao.cmdMySql.ExecuteNonQuery();
                    MessageBox.Show("Registro salvo com sucesso", "Salvar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageBox.Show("Alterado com sucesso", "Alterar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

And this is the error message that happens and the part of the code that he is referencing:

Conexao.reader = Conexao.cmdMySql.ExecuteReader();
            while (Conexao.reader.Read())
            { //repete até finalizar os campos

                ListViewItem list = new ListViewItem(Conexao.reader[0].ToString()); //este comando é um objeto que liga sa informações do banco para o componente grafico list view organizando por índice.
                                                                                    //O índice 0 representa a coluna do ID que está oculta
                list.SubItems.Add(Conexao.reader[1].ToString());
                list.SubItems.Add(Conexao.reader[2].ToString());
                list.SubItems.Add(Conexao.reader[3].ToString());
                list.SubItems.Add(Conexao.reader[4].ToString());
                list.SubItems.Add(Conexao.reader[5].ToString());
                list.SubItems.Add(Conexao.reader[6].ToString());
                //Exibe os dados das colunas. Ocultando a coluna ID.

                event_lstv.Items.AddRange(new ListViewItem[] { list });
            }
            Conexao.reader.Close();

        }
    
asked by anonymous 05.06.2016 / 18:36

0 answers