How to delete record in SqlCe Db for windows phone

Traitée How to delete record in SqlCe Db for windows phone

  • lunes, 06 de agosto de 2012 8:11
     
     

    Have two tables ;  Master  and child as below:


    tblMaster
    ==========
    MId
    DateOfTransact
    Note


    tblChild
    ======
    Cid
    Mid
    TypeOfTransaction
    Time
    Amount

    Questions:

    1. How to delete all the Records in Tables Master and child?

     

Todas las respuestas

  • lunes, 06 de agosto de 2012 10:19
    Moderador
     
     

    Get all records from tblChild, delete them, submitchanges, get all records fro tblMaster, delete them, submit changes. See some sample code here: http://erikej.blogspot.dk/2012/04/windows-phone-local-database-tip.html


    Please mark as answer, if this was it. Visit my SQL Server Compact blog

  • lunes, 06 de agosto de 2012 11:31
     
     Respondida

    Thanks for the link. Here the two methods.

    Can use method 1 into Method 2 where :

    context3.tblChild.DeleteOnSubmit(Rcd)  instead using foreach- statement?


    ===================

    Method 1:
    -----------
    var list = db.InvoiceLine.Take(100);      
    db.InvoiceLine.DeleteAllOnSubmit(list);

     

    Method 2
    -------------
      using (DbTransact  context3 = new DbTransact(ConnectionString))
     {          
     var Rcd = from c in tblChild                         
                    where c.Mid == Convert.ToInt32(strIdNo)                         
                    select c;

      foreach (var c in Rcd )
                        {
                            context3.tblChild.DeleteOnSubmit(c);
                        }

      context3.SubmitChanges();

    }