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();
}
}