How can different dates be inserted from an incremental loop from c # to MySql?

-1

What I want to achieve is to insert several dates per month incrementally with a loop and insert them into a MySql table.

I have already made a loop that generates more than one record, but it does not take different dates from the loop that I made for the dates, it only takes me one that is the one that entered. If you do it in a listbox or listview , also in label but placing more than one I leave the codes and images.

This code is my login button:

int valor = txtplazo.SelectedIndex;
DateTime date1 = txtfcaducidad.Value;
Fechas Fechas = new Fechas();
Fechas.nomcompromiso = txtnomcompr.Text;
Fechas.plazo = txtplazo.Text;
Fechas.fdepago = txtfdeplazo.Value.ToString("yyyy-MM-dd");

for (int i = 1; i < 2; i++)
{
    Fechas.fcaducidad = date1.AddMonths(i).ToString("yyyy-MM-dd");
}

Fechas.valordecuota = txtvalorcuota.Text;
Fechas.pago = txtpago.Text;
Fechas.formadepago = txtformapago.Text;
int resultado = DALFechas.Agregar(Fechas);

Here is my code where you make insert with the loop to enter more than one record:

for (int i = 0; i < 10; i++)
{
    using (MySqlConnection Conn = BDcomun.ObtnerCOnexion())
    {
        MySqlCommand Comando = new MySqlCommand(string.Format("Insert Into compromisos (nomcompromiso, tipodeplazo, fdepago, fcaducidad, valordecuota, pago, formadepago) values ('{0}', '{1}', NULL, @fdecaducidad, '{4}', NULL, NULL)",
                    pfechas.nomcompromiso, pfechas.plazo, pfechas.fdepago, pfechas.fcaducidad, pfechas.valordecuota, pfechas.pago, pfechas.formadepago), Conn);

        Comando.Parameters.AddWithValue("@fdecaducidad", pfechas.fcaducidad);
                    MySqlDataAdapter da = new MySqlDataAdapter(Comando);
                    retorno = Comando.ExecuteNonQuery();
                    Conn.Close();

    }
}

    
asked by Jonathan Alex Córdova Hurtado 27.09.2018 в 13:38
source

1 answer

0

I was able to do it through a query to MySql, the idea is to make a separate table called integers in the same database insert a record of whole numbers from 0 to 9, with between you can give the number of records in this case I put from 0 to 9 would be 10 records with this is not necessary to make a loop in this case.

This what would insert several records and on the date which you chose to be placing it per month incrementally, this can be modified, if you want annual serious year or day, day, the selection after insert into act as the value in this case.

 "INSERT INTO compromisoss (nomcompromisos, tipodeplazo, fdepago, fcaducidad, valordecuota, pago, formadepago) 
                                                                                SELECT '{0}', '{1}', NULL, ADDDATE('{3}', INTERVAL SomeNumber month), '{4}', null, null                                                                               FROM (SELECT a.i+b.i*10+c.i*100+d.i*1000 AS SomeNumber FROM enteros a, enteros b, enteros c, enteros d) Sub1 WHERE SomeNumber BETWEEN 0 AND 9"
    
answered by 05.10.2018 в 13:58