Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
- {
- con.Open();
- 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);
- cmd.Parameters.AddWithValue("@EmployeeName", dataGridView1.Rows[i].Cells[0].Value);
- cmd.Parameters.AddWithValue("@Department", dataGridView1.Rows[i].Cells[1].Value);
- cmd.Parameters.AddWithValue("@SIC", dataGridView1.Rows[i].Cells[2].Value);
- cmd.Parameters.AddWithValue("@Team", dataGridView1.Rows[i].Cells[3].Value);
- cmd.Parameters.AddWithValue("@Designation", dataGridView1.Rows[i].Cells[4].Value);
- DateTime date1 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[5].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@StartDate",date1);
- DateTime date2 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[6].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@EndDate", date2);
- cmd.Parameters.AddWithValue("@LeaveType", dataGridView1.Rows[i].Cells[7].Value);
- cmd.Parameters.AddWithValue("@TotalDays", Convert.ToInt32(dataGridView1.Rows[i].Cells[8].Value));
- cmd.Parameters.AddWithValue("@Comment", dataGridView1.Rows[i].Cells[9].Value);
- cmd.Parameters.AddWithValue("@SupervisorComment", dataGridView1.Rows[i].Cells[10].Value);
- cmd.Parameters.AddWithValue("@HRComment", dataGridView1.Rows[i].Cells[11].Value);
- cmd.Parameters.AddWithValue("@OMComment", dataGridView1.Rows[i].Cells[12].Value);
- cmd.Parameters.AddWithValue("@DRComment", dataGridView1.Rows[i].Cells[13].Value);
- DateTime date3 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[14].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@DateOfSubmission", date3);
- cmd.Parameters.AddWithValue("@Supervisor", dataGridView1.Rows[i].Cells[15].Value);
- cmd.Parameters.AddWithValue("@HR", dataGridView1.Rows[i].Cells[16].Value);
- cmd.Parameters.AddWithValue("@Office_Manager", dataGridView1.Rows[i].Cells[17].Value);
- cmd.Parameters.AddWithValue("@Director", dataGridView1.Rows[i].Cells[18].Value);
- DateTime date4 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[19].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@DateOfApprovalOM", date4);
- DateTime date5 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[20].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@DateOfApprovalSupervisor", date5);
- DateTime date6 = DateTime.ParseExact((dataGridView1.Rows[i].Cells[21].Value).ToString(), "dd-MM-yy h:mm", System.Globalization.CultureInfo.InvariantCulture);
- cmd.Parameters.AddWithValue("@DateOfApprovalHR", date6);
- cmd.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("Records inserted.");
- }
Add Comment
Please, Sign In to add comment