Getting the error “cannot add an entity that already exists.” while inserting a table's value in to DB without procedure

前端 未结 5 1625
谎友^
谎友^ 2021-01-21 05:15

I am inserting a list of records to the DB table with Linq to sql like this:

//my DataContext Class
 using (VTMMedicalDBDataContext objVTMMedicalDBDataContext =          


        
5条回答
  •  醉话见心
    2021-01-21 05:53

    Finally After Much hassle I got my answer with a new concept..

    For all those facing similar problems,here is a clear solution:

    You need to create the object of the 'Table' class(which object you want to update in DB), inside the loop(*for each,for or any other..)so that same record is not updated and each object uses a different memory location(as the local instance gets destroyed inside the loop only..)*

提交回复
热议问题