Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void SAVEBUTTON_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow row in dataGridView1.Rows)// picks data from dataGridview
- {
- try // MySql connection
- {
- String constring = "datasource=;port=3306;username=;password=";
- MySqlConnection connection = new MySqlConnection(constring);
- MySqlCommand cmd = new MySqlCommand();
- cmd = connection.CreateCommand();
- //
- if (row.IsNewRow) continue;
- cmd.Parameters.AddWithValue("@MatriculeOPerateur", row.Cells["matriculeOPDataGridViewTextBoxColumn2"].Value);
- cmd.Parameters.AddWithValue("@N_de_configuration_des_postes_de_travail", row.Cells["ndeconfigurationdespostesdetravailDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@Filiere", row.Cells["filiereDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@date", row.Cells["dateDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@N_OF", row.Cells["nOFDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@Quantite", row.Cells["quantiteDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@Qualite_NC", row.Cells["qualiteNCDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@commentaire", row.Cells["commentaireDataGridViewTextBoxColumn"].Value);
- cmd.Parameters.AddWithValue("@formateur", row.Cells["nometprenomDataGridViewTextBoxColumn1"].Value);
- formationEntities dc = new formationEntities();
- string N = Convert.ToString(row.Cells[8].Value);
- var getMatricule = dc.responsableTable.Where(b => b.formateur== N).SingleOrDefault();
- int matres = getmatricule.MatriculeRes;
- string operator = Convert.ToString(row.Cells[0].Value);
- string poste = Convert.ToString(row.Cells[1].Value);
- string filiere = Convert.ToString(row.Cells[2].Value);
- string date = Convert.ToString(row.Cells[3].Value);
- string of = Convert.ToString(row.Cells[4].Value);
- string quant = Convert.ToString(row.Cells[5].Value);
- string qual = Convert.ToString(row.Cells[6].Value);
- string com = Convert.ToString(row.Cells[7].Value);
- cmd.CommandText = "INSERT INTO formation.modelPosteTable (N_de_configuration_des_postes_de_travail,Filiere,MatriculeRes,MatriculeOP,date,N_OF,Quantite_NC,commentaire)VALUES('" + poste + "','" + filiere + "','" + operator + "','" + matres + "','" +date + "','" + of + "','" + quant + "','" + qual + "','" + com + "')";
- connection.Open();
- cmd.ExecuteNonQuery();
- connection.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- MessageBox.Show("data inserted.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement