0
delete  from detail where autoid not in (select min(autoid) from detail
where CATEGORY<>'Accepted'
group by ATM_Id, Date, Card ,Transit ,Ck)
and CATEGORY<>'Accepted'

what I was tried

     var Query2 = from line in
     (from line in source let fields = line.Split(',')
     select new {  autoid = fields[0],
          ATMID = fields[4],
          DATE = fields[2],
          CARDNo = fields[5],
          TRANSIT = fields[8],
          CheckNo = fields[9],
          CATEGORY = fields[10],
      })
      orderby line.ATMID, 
              line.DATE, 
              line.CARDNo, 
              line.TRANSIT, 
              line.CheckNo ascending
      where   line.CATEGORY != "Accepted"
      group line by new {   line.ATMID,
                            line.DATE, 
                            line.CARDNo, 
                            line.TRANSIT, 
                            line.CheckNo } 
      into gruoped
      where gruoped.Count() > 1

                 //select autoid = gruoped.Key;
      select new
      {
                     //ATMID = gruoped.Key,
                     //DATE = gruoped.Key,
                     //CARDNo = gruoped.Key,
                     //TRANSIT = gruoped.Key,
                     //CheckNo = gruoped.Key,
                     autoid = gruoped.Key,
                     //CATEGORY = gruoped.Key
      };

2 Answers 2

0

Here is a sample how it should work check this out

var remove = (from aremove in db.logins 
             where aremove.username == userNameString 
                && aremove.Password == pwdString 
             select aremove).FirstOrDefault(); 

if(remove != null)
{
    db.logins.DeleteOnSubmit(remove);
}

If you have any question fell free to ask !!

2
  • ok..but i am not using DataBase,my detail database is a comma separated text file, from that i need to delete duplicated lines...is it possible to delete duplicated lines..thank you Commented Jun 13, 2013 at 6:38
  • @user2448680 You should tried your self .. and if you have problem ask a question
    – Mingebag
    Commented Jun 13, 2013 at 10:58
0

You can try this.

var ids = (from d in detail
where d.Category != "Accepted"
group d by new {d.ATM_Id, d.Date, d.Card ,d.Transit ,d.Ck} into grp
select  grp.Min(x => x.autoId));


var toDelete = (from d in detail
            where !ids.Contains(d.AutoId) && d.Category != "Accepted"
            select d);

context.DeleteOnSubmit(toDelete);   

You can just search for the ones you want and then recreate your new list of comma separated strings to store back to a file.

EG:

void Main()
{

    var fields = new List<Field>{
        new Field{Id = 1, Name = "A"},
        new Field{Id = 1, Name = "A"},
        new Field{Id = 2, Name = "B"},
        new Field{Id = 1, Name = "A"},
        new Field{Id = 3, Name = "C"},
        new Field{Id = 2, Name = "B"},
    };

    // Grouped 
    var grouped = (from f in fields
                group f by new {f.Id, f.Name} into grp
                select new Field
                {
                        Id = grp.Select(x => x.Id).FirstOrDefault(),
                        Name = grp.Select(x => x.Name).FirstOrDefault()
                }
                );

    // Makes a list of the distinct Fields             
    var list_Of_CSV_Items = grouped.Select(x => string.Join(",", x.Id,x.Name));

    System.IO.File.WriteAllLines(@"C:\Where_your_folder_is.txt", list_Of_CSV_Items);
}

public class Field
{
    public int Id {get;set;}
    public string Name {get; set;}
}         
5
  • context.DeleteOnSubmit(toDelete); after this statement giving some error..like query body must end with select or group clause.. Commented Jun 12, 2013 at 18:10
  • sorry see edit, just added select d. I used a text editor to do this. also the context is your DataContext so swap it for whatever your DataContext instance is named.
    – crackhaus
    Commented Jun 12, 2013 at 18:20
  • ok..but i am not using DataContext,my detail database is a comma separated text file, from that i need to delete duplicated lines...is it possible to delete duplicated lines..thank you.. Commented Jun 13, 2013 at 6:37
  • Added something for you to try out and apply to your code. It takes the unique items and creates a new list of comma separated strings for you to store back to your file or whatnot.
    – crackhaus
    Commented Jun 13, 2013 at 18:16
  • thanks i got this...but the next problem is , i have a text file with more than 2(2000000) lack rows so it is not producing result..but it is working up to 1000 rows... Commented Jun 14, 2013 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.