Prabu Baskaran

Prabu Baskaran

  • NA
  • 1
  • 893

I have a scenario in C# using linq... pls guide me

Aug 19 2014 2:13 AM
creating a table with primary key as ID.
using linq i am checking the date.
 
eg:  1st .txt file has this values.
ID,name,Valid_END_DATE
1,raja,15-07-2013
2,ram,13-08-2014
 
2nd .txt file has this values
ID,name,Valid_END_DATE
1,raja,15-07-2014       //condition checks   
2,ram,13-08-2014 
 
 
//---->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. 
 
 
Exactly what i need in database
1,raja,15-07-2013
2,ram,13-08-2014
3,raja,15-07-2014 
 
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
 

Answers (1)