I have an excel sheet with 4 column(JobCode,JobName,StartDate,EndDate). On the basis of one rule I have to validate the 1st excel sheet and insert all the record in 2nd excel sheet except the duplicate record which is present in 1st excel sheet. I tried to using list. But it's working as expected.
List<string> JobCodeList = new List<string>();
for (int iRowCount = 0; iRowCount < hrms_jobdata.Tables[0].Rows.Count; iRowCount++)
{
JobCode = hrms_jobdata.Tables[0].Rows[iRowCount]["Job Code"].ToString();
JobName = hrms_jobdata.Tables[0].Rows[iRowCount]["Job Name"].ToString();
StartDate = hrms_jobdata.Tables[0].Rows[iRowCount]["Start Date"].ToString();
EndDate = hrms_jobdata.Tables[0].Rows[iRowCount]["End Date"].ToString();
JobCodeList.Add(JobCode + JobName);
}
connectionhrms_job.Close();
for (int iRowCount = 0; iRowCount < hrms_jobdata.Tables[0].Rows.Count; iRowCount++)
{
JobCode = hrms_jobdata.Tables[0].Rows[iRowCount]["Job Code"].ToString();
JobName = hrms_jobdata.Tables[0].Rows[iRowCount]["Job Name"].ToString();
StartDate = hrms_jobdata.Tables[0].Rows[iRowCount]["Start Date"].ToString();
EndDate = hrms_jobdata.Tables[0].Rows[iRowCount]["End Date"].ToString();
DateTime convertedstart = DateTime.Parse(StartDate);
StartDateFormated = convertedstart.ToString("dd-MM-yyyy");
DateTime convertedend = DateTime.Parse(EndDate);
EndDateFormated = convertedend.ToString("dd-MM-yyyy");
List<string> dupvalue = removeDuplicates(JobCodeList);
foreach (string value in dupvalue)
{
string jobcodename = value;
}
string connectionStringdest = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathdestination + ";Extended Properties=Excel 12.0;";
DbProviderFactory factorydest = DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection connectiondest = factorydest.CreateConnection();
connectiondest.ConnectionString = connectionStringdest;
DbCommand command = connectiondest.CreateCommand();
StringBuilder inserthrms_job = new StringBuilder();
inserthrms_job = inserthrms_job.Append("Insert into [hrms_job$] values ('" + JobCode + "', '" + JobName + "', '" + StartDateFormated + "', '" + EndDateFormated + "','" + JobCode + " " + JobName + "') ");
inserthrms_job = inserthrms_job.Append(";");
command.CommandText = inserthrms_job.ToString();
connectiondest.Open();
command.ExecuteNonQuery();
connectiondest.Close();
}