Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. private void SAVEBUTTON_Click(object sender, EventArgs e)
  2. {
  3. foreach (DataGridViewRow row in dataGridView1.Rows)// picks data from dataGridview
  4. {
  5. try // MySql connection
  6. {
  7. String constring = "datasource=;port=3306;username=;password=";
  8. MySqlConnection connection = new MySqlConnection(constring);
  9.  
  10. MySqlCommand cmd = new MySqlCommand();
  11. cmd = connection.CreateCommand();
  12.  
  13. //
  14. if (row.IsNewRow) continue;
  15. cmd.Parameters.AddWithValue("@MatriculeOPerateur", row.Cells["matriculeOPDataGridViewTextBoxColumn2"].Value);
  16. cmd.Parameters.AddWithValue("@N_de_configuration_des_postes_de_travail", row.Cells["ndeconfigurationdespostesdetravailDataGridViewTextBoxColumn"].Value);
  17. cmd.Parameters.AddWithValue("@Filiere", row.Cells["filiereDataGridViewTextBoxColumn"].Value);
  18. cmd.Parameters.AddWithValue("@date", row.Cells["dateDataGridViewTextBoxColumn"].Value);
  19. cmd.Parameters.AddWithValue("@N_OF", row.Cells["nOFDataGridViewTextBoxColumn"].Value);
  20. cmd.Parameters.AddWithValue("@Quantite", row.Cells["quantiteDataGridViewTextBoxColumn"].Value);
  21. cmd.Parameters.AddWithValue("@Qualite_NC", row.Cells["qualiteNCDataGridViewTextBoxColumn"].Value);
  22. cmd.Parameters.AddWithValue("@commentaire", row.Cells["commentaireDataGridViewTextBoxColumn"].Value);
  23. cmd.Parameters.AddWithValue("@formateur", row.Cells["nometprenomDataGridViewTextBoxColumn1"].Value);
  24.  
  25. formationEntities dc = new formationEntities();
  26. string N = Convert.ToString(row.Cells[8].Value);
  27. var getMatricule = dc.responsableTable.Where(b => b.formateur== N).SingleOrDefault();
  28.  
  29. int matres = getmatricule.MatriculeRes;
  30. string operator = Convert.ToString(row.Cells[0].Value);
  31. string poste = Convert.ToString(row.Cells[1].Value);
  32. string filiere = Convert.ToString(row.Cells[2].Value);
  33. string date = Convert.ToString(row.Cells[3].Value);
  34. string of = Convert.ToString(row.Cells[4].Value);
  35. string quant = Convert.ToString(row.Cells[5].Value);
  36. string qual = Convert.ToString(row.Cells[6].Value);
  37. string com = Convert.ToString(row.Cells[7].Value);
  38.  
  39. 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 + "')";
  40. connection.Open();
  41. cmd.ExecuteNonQuery();
  42. connection.Close();
  43. }
  44. catch (Exception ex)
  45. {
  46. MessageBox.Show(ex.Message);
  47. }
  48. }
  49. MessageBox.Show("data inserted.");
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement