Guest User

Untitled

a guest
Oct 23rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
  2. {
  3. con.Open();
  4. SqlCommand cmd = new SqlCommand("INSERT INTO Leave VALUES(@EmployeeName,@Department,@SIC,@Team,@Designation,@StartDate,@EndDate,@LeaveType,@TotalDays,@Comment,@SupervisorComment,@HRComment,@OMComment,@DRComment,@DateOfSubmission,@Supervisor,@HR,@Office_Manager,@Director,@DateOfApprovalOM,@DateOfApprovalSupervisor,@DateOfApprovalHR",con);
  5. cmd.Parameters.AddWithValue("@EmployeeName", dataGridView1.Rows[i].Cells[0].Value);
  6. cmd.Parameters.AddWithValue("@Department", dataGridView1.Rows[i].Cells[1].Value);
  7. cmd.Parameters.AddWithValue("@SIC", dataGridView1.Rows[i].Cells[2].Value);
  8. cmd.Parameters.AddWithValue("@Team", dataGridView1.Rows[i].Cells[3].Value);
  9. cmd.Parameters.AddWithValue("@Designation", dataGridView1.Rows[i].Cells[4].Value);
  10. DateTime date1 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[5].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  11. cmd.Parameters.AddWithValue("@StartDate",date1);
  12. DateTime date2 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[6].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  13. cmd.Parameters.AddWithValue("@EndDate", date2);
  14. cmd.Parameters.AddWithValue("@LeaveType", dataGridView1.Rows[i].Cells[7].Value);
  15. cmd.Parameters.AddWithValue("@TotalDays", Convert.ToInt32(dataGridView1.Rows[i].Cells[8].Value));
  16. cmd.Parameters.AddWithValue("@Comment", dataGridView1.Rows[i].Cells[9].Value);
  17. cmd.Parameters.AddWithValue("@SupervisorComment", dataGridView1.Rows[i].Cells[10].Value);
  18. cmd.Parameters.AddWithValue("@HRComment", dataGridView1.Rows[i].Cells[11].Value);
  19. cmd.Parameters.AddWithValue("@OMComment", dataGridView1.Rows[i].Cells[12].Value);
  20. cmd.Parameters.AddWithValue("@DRComment", dataGridView1.Rows[i].Cells[13].Value);
  21. DateTime date3 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[14].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  22. cmd.Parameters.AddWithValue("@DateOfSubmission", date3);
  23. cmd.Parameters.AddWithValue("@Supervisor", dataGridView1.Rows[i].Cells[15].Value);
  24. cmd.Parameters.AddWithValue("@HR", dataGridView1.Rows[i].Cells[16].Value);
  25. cmd.Parameters.AddWithValue("@Office_Manager", dataGridView1.Rows[i].Cells[17].Value);
  26. cmd.Parameters.AddWithValue("@Director", dataGridView1.Rows[i].Cells[18].Value);
  27. DateTime date4 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[19].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  28. cmd.Parameters.AddWithValue("@DateOfApprovalOM", date4);
  29. DateTime date5 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[20].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  30. cmd.Parameters.AddWithValue("@DateOfApprovalSupervisor", date5);
  31. DateTime date6 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[21].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
  32. cmd.Parameters.AddWithValue("@DateOfApprovalHR", date6);
  33.  
  34.  
  35. cmd.ExecuteNonQuery();
  36. con.Close();
  37.  
  38. MessageBox.Show("Records inserted.");
  39. }
Add Comment
Please, Sign In to add comment