Search This Blog

Tuesday, October 21, 2014

VB.NET LINQ TO SQL Delete Rows From Database

ADO.NET > LINQ TO SQL > Delete rows from database

DeleteOnSubmit removes entity, but does not disappear from the query results until after SubmitChanges is called. 

Example


C#

var deleteData =
    from details in db.GetDetails
    where details.ID == 1
    select details;

foreach (var detail in deleteData )
{
    db.Details.DeleteOnSubmit(detail);
}

try
{
    db.SubmitChanges();
}
catch (Exception e)
{
}



VB.Net

Dim deleteData = _
    From details In db.GetDetails() _
    Where details.ID = 1 _
    Select details

For Each detail As Detail In deleteData
    db.Details.DeleteOnSubmit(detail)
Next 

Try
    db.SubmitChanges()
Catch ex As Exception

End Try