creating a table with primary key as ID.
using linq i am checking the date.
eg: 1st .txt file has this values.
//---->here the condition checks if it's true it should create a new ID(eg)3 and update the value in the database, else(ie) false it should update with Same ID.
here is my coding. using c#
CultureInfo enGB = new CultureInfo("en-GB");
DateTime CheckDate = DateTime.Parse(csv[12], enGB);
string primary = csv[0].ToString(); //Primary key from this Table.
if (!string.IsNullOrEmpty(primary))
{
using (EntityModel entities = new EntityModel())
{
SSS objRMPRC = (from o in entities.SSSs
where o.ID == primary && o.VALID_END_DATE <= CheckDate
select o).FirstOrDefault();
if (objRMPRC == null)
{
objRMPRC = SSS.CreateSSS(primary);
entities.AddToSSSs(objRMPRC);
}
for (int i = 0; i < fieldCount; i++)
{
string ss = csv[i].ToString(); // to check the values.
csv.SkipEmptyLines = true;// Skips Empty line
if (i == 12) //Datetime Format Column values
{ //en-GB: dd/MM/yyyy (e.g. 14/03/2012)
//CultureInfo enGB = new CultureInfo("en-GB"); //en-US: M/d/yyyy (e.g. 3/14/2012)
DateTime MyDateTime = DateTime.Parse(csv[i], enGB); //Language is set to UK english (en-GB) in windows control panel and web.config.
objRMPRC.GetType().GetProperty(headers[i]).SetValue(objRMPRC, MyDateTime, null);
}
else
{
objRMPRC.GetType().GetProperty(headers[i]).SetValue(objRMPRC, csv[i], null);
}
}
entities.SaveChanges(); //Save the Lines into Database.
}//using
}//if