.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Is the delete records LINQ correct ?

Posted By:      Posted Date: September 11, 2010    Points: 0   Category :ASP.Net
 
I hope to delete all records in DBPrograms, is the following code correct?               DBContext db = DBContext(PublicDBPar.ConnectionString);            db.DBPrograms.DeleteAllOnSubmit(db.DBPrograms);            db.SubmitChanges();


View Complete Post


More Related Resource Links

ReadOnly DateTime attribute stores correct date but only retrieves DateTime.MinValue on Delete

  

Hey everyone,

I have a dynamic data site that stores Event data using LINQ-to-SQL. When someone requests an event, it is first stored as a PendingEvent (which is a child of Event) with a column/attribute called receivedAt, which is [ReadOnly(true)] and which is assigned in InsertEvent as shown.

        partial void InsertEvent(Event instance)
        {
            instance.requestedAt = DateTime.Now;

            SendEmail(instance);

            instance.AddEventToCalendar();

            this.ExecuteDynamicInsert(instance);
        }


This works fine. The event displays with the correct receivedAt date, and it's correct in my database. It shows up just fine on my Display, Edit, and List pages. However, if I try to delete, the receivedAt in the instance (retrieved with my debugger) in my delete function is 01/01/0001 12:00am, also known as DateTime.MinValue. My other dates appear correct.

If I remove "ReadOnly(true)" from the received at, everything works fine. Why won't "ReadOnly" allow me to have a time?
Thanks in advance,

Andrew

Addendum:

I forgot to mention why I care. I can't submit the instance to be deleted because DateTime.MinValue is outside SQL's available datetime, so I get a SQL error. The delete also takes place in a custom dele

Problem updating records with LINQ, Concurrency?

  
 My project includes a grid view with some updtable fields, some fields throw an error on update and some do not and it does not really make sense. WORK_STATION_ID does not cause an error, ROOM _ID cause an error, both are int? (I am using c#) and for update I use the code liste below.using (DataClassesDataContext db = new DataClassesDataContext()) { var product = (from p in db.ASSETs where p.ASSET_ID == ASSET_ID select p).Single(); product.WORK_STATION_ID=WORK_STATION_ID; product.ROOM_ID=ROOM_ID; db.SubmitChanges(); }    Row not found or changed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.Linq.ChangeConflictException: Row not found or changed. Source Error: Line 93: Line 94: Line 95: db.SubmitChanges(); Line 96: Line 97: Source File: C:\Projects\TEST_II\trunk\ObjectDataSourceLibrary\AssetController.cs Line: 95 Stack Trace: [ChangeConflictException: Row not found or changed.] System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +963417 Syst

delete a row in datatable using linq to dataset

  
hihow can i delete a row in datatable using linq to dataset?I have a dataset in my project, need to delete some rows filtered by IDhow can i do?

Allow or deny roles to update, insert and delete records.

  
Hello, I have two roles "Admin" and "Basic". I also have a listview on the web page. My goal is that to make "Admin" role has the highest privilege to deal with records such as "insert", "update" and "delete". For the role "Basic", it only can update the records. Is there any sample code for that? Thanks.  

I have relation many to many - how can I delete records from intermediate table ?

  
I have tables: Books id title Authors id name BooksAuthors book_id author_id Entity Framework generated only models for tables Books and Authors in relation many to many. How can I delete from table BooksAuthors all records where book_id =5 ?

Delete Multiple Records

  
Hai friends,            How to delete multiple records using checkbox in gridview?

LINQ - Can't perform Create, Update or Delete operations on because it has no primary key.

  
Hi, not sure if I'm posting this thread in the right section. anyway, I''m trying to do the update/insert/delete using LINQ but the underlying table does not a primary key. The table consists of composite ket (e.g. fieldA & FieldB make a primary key). At the moment, I have LINQ complaning about not having a single primary key (not sure what LINQ does it - not making any sense at all). did anyone ever come across this issue and rectified it?  thanks

how to delete records automatically at server side

  
the application which i created is a web application which doesnt need much of a database,so i am just using the sql express  free version which allows 4 gb of data,to avoid disasters iw ould like to delete records which are very old like,1 month,2 months old etc,how can i do this periodically should i do this on client side or the server side... what id there are 100000 records and if we put this in page load or some method,it could take some time to delete,which i dont want..........can anyone suggest how i can automate this process at the server side only Please help me... thanks  

How to delete many records with minimal locks and IO?

  
hi, I have a larg db (160GB) that used both as OLTP and DW. there are several large tables that normally experience 10k-30k transactions per hour. most of them are INSERT and part are UPDATE. Tables have cluster PK of 5-8 fields with datetime one of them. tables have several indexes. normally we dont delete records. BUT, end-user may quit service once in a while and in this case we have a job to delete all his raw data. we have a job that tries to do it in small chunks to reduce impact on other processing jobs, but actually it slows down all other important transactions with long locks. I would like to know what is the best way to delete records from a large table with minimum impact on other transactions (insert and update). The delete task is a background job that is executed during night and may take many hours. here is my code: ALTER     PROCEDURE SP_ADMIN_DEL_DATA     @CompanyID int,     @itemID nvarchar(50) = '-1' AS begin     -- @itemID = -1 for all items     declare @d datetime     declare @upperDate datetime       set @upperDate = dbo.FN_DateOnly(getdate() + 1)     set @d = @upperDate - 800     while @d <= @upperDate     begin     begin tran     DELETE I_EVENTS with (PAGLOC

How to delete many records with minimal locks and IO?

  
How to delete many records with minimal locks and IO? hi, I have a larg db (160GB) that used both as OLTP and DW. there are several large tables that normally experience 10k-30k transactions per hour. most of them are INSERT and part are UPDATE. Tables have cluster PK of 5-8 fields with datetime one of them. tables have several indexes. normally we dont delete records. BUT, end-user may quit service once in a while and in this case we have a job to delete all his raw data. we have a job that tries to do it in small chunks to reduce impact on other processing jobs, but actually it slows down all other important transactions with long locks. I would like to know what is the best way to delete records from a large table with minimum impact on other transactions (insert and update). The delete task is a background job that is executed during night and may take many hours. here is my code: ALTER @CompanyID     int, @itemID     nvarchar(50) = '-1' AS begin -- @itemID = -1 for all items declare     @d   declare     @upperDate   set     @upperDate = dbo.FN_DateOnly(getdate() + 1) set     @d = @upperDate - 800 while     @d <= @upperDate begin begin     tran DELETE       I_EVENTS with (PAGLOCK) WHERE     G_COMPANY_ID

linq - delete dropdownlist

  
My code:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"DataSourceID="LinqDataSource1" DataTextField="UserId" DataValueField="UserId"></asp:DropDownList>BurnbetDataDataContext db = new BurnbetDataDataContext();        var selectedID = (DropDownList1.SelectedValue);        tbl_Payment toDelete = db.tbl_Payments.Single(p => p.UserId == selectedID);        db.tbl_Payments.DeleteOnSubmit(toDelete);        db.SubmitChanges();Error:System.InvalidOperationException was unhandled by user code  Message=Sequence contains more than one element  Source=System.Data.Linq  StackTrace:       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IPr

linq - delete two tables not work

  
BurnbetDataContext db = new BurnbetDataContext(); var q = (from c in db.GetTable<tbl_Payment>() where c.UserId == "fc44c835-8e80-45ee-af84-68339a09c053" select c).Single<tbl_Payment>(); db.GetTable<tbl_Payment>().DeleteOnSubmit(q); db.SubmitChanges(); In App_Code I BurnbetDataContext.I have two tables and tbl_PaymentDetails tbl_PaymentAssociation is:Parent Child Class -->>> UserId UserId ClassData in Table tbl_PaymentDetails (child) does not delete.      

MS Linq To SQL Samples - Insert/Update/Delete

  
Hi, I'm stumbling along trying my hand at Linq to SQL and have come across this code below that was provided by MS.http://msdn.microsoft.com/en-us/vbasic/bb737928.aspxThe problem is there is no ".add" method for Categories to chose in the statement db2.Categories.add(newCategory)I've seen similar videos here on ASP .NET that uses code very much like the example below, but I am unable to run this example connected to a Northwind SQL database using Web Developer 2010 Express. This is the One-to-Many example listed under Linq To SQL Samples - Insert/Update/Delete. Thanks for any help! Shawn Dim db2 = New DataClassesDataContext Dim ds = New DataLoadOptions() ds.LoadWith(Of Category)(Function(p) p.Products) db2.LoadOptions = ds Dim newCategory = New Category With {.CategoryName = "Widgets", _ .Description = "Widgets are the customer-facing analogues " & _ "to sprockets and cogs.", _ .Picture = Nothing} Dim newProduct = New Product With {.ProductName = "Blue Widget", _ .UnitPrice = 34.56#, _ .Category = newCategory, _

How to delete many records with minimal locks and IO?

  
How to delete many records with minimal locks and IO? hi, I have a larg db (160GB) that used both as OLTP and DW. there are several large tables that normally experience 10k-30k transactions per hour. most of them are INSERT and part are UPDATE. Tables have cluster PK of 5-8 fields with datetime one of them. tables have several indexes. normally we dont delete records. BUT, end-user may quit service once in a while and in this case we have a job to delete all his raw data. we have a job that tries to do it in small chunks to reduce impact on other processing jobs, but actually it slows down all other important transactions with long locks. I would like to know what is the best way to delete records from a large table with minimum impact on other transactions (insert and update). The delete task is a background job that is executed during night and may take many hours. here is my code: ALTER @CompanyID     int, @itemID     nvarchar(50) = '-1' AS begin -- @itemID = -1 for all items declare     @d   declare     @upperDate   set     @upperDate = dbo.FN_DateOnly(getdate() + 1) set     @d = @upperDate - 800 while     @d <= @upperDate begin begin     tran DELETE       I_EVENTS with (PAGLOCK) WHERE     G_COMPANY_ID

Delete records if it is not getting inserted and also in the related tables

  
Hi All, If the insert into table person is successful, but the insert into table subject fails, delete the person record and all records associated with the person that were also inserted. If the insert into table person is successful, and the insert into subject is successful, but the insert into the booking table fails, delete the subject record, the person record ,and all records associated with the person that were also inserted. The reason for the failure into the 3 tables (person, subject, booking) should be logged to tblErrors . Also, a message should be written to tblErrors which logs the fact that this situation has occurred.     -- I have few stored procs which does inserts and updates How would i capture the record which is not getting inserted and log in to log table and delete the previous records which got inserted  which are related to that.

Delete Duplicate Records from MySQL table

  

I have Revision column in Quote table with time stamp (MySql table) now i am viewing the entire date and time my end user want to view only Date he doesnot want to see time how can i pull only date.i am displaying revision column in two ways one in grid view and another one in field value

Query in my Grid view
Dim query As String = "SELECT QuoteNumber,Revision,Vendor,PartNumber,status,Customer,Requestor from quotes"
On select check box in grid view, filed values will be loaded with data.

field value
txtRev.Text = dt.Rows(indx)("Revision").ToString()

 

 

 


how to delete records from multiple tables.

  

Hi Friends,Tell me How to delete records from multiple tables by using a single query.


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend