Solved

LINQ TO SQL add new records (C#)

Posted on 2009-04-01
2
534 Views
Last Modified: 2013-11-11
I have the following code to add new records to table, but the data is not saved in database. Any ideas what
could be the problem ? (list is not empty)
public bool PostInvoice(IList<tbAffiliatePostedReservation> reslist)
       {
           DBClasesDataContext dbcontext = new DBClasesDataContext();
           dbcontext.tbAffiliatePostedReservations.AttachAll(reslist);
           dbcontext.SubmitChanges();
           return true;
       }

Open in new window

0
Comment
Question by:crcsupport
2 Comments
 
LVL 9

Accepted Solution

by:
cdaly33 earned 500 total points
ID: 24044633
If you're look to do an insert then I think you want InsertAllOnSubmit.
public bool PostInvoice(IList<tbAffiliatePostedReservation> reslist)
       {
           DBClasesDataContext dbcontext = new DBClasesDataContext();
           dbcontext.tbAffiliatePostedReservations.InsertAllOnSubmit(reslist);
           dbcontext.SubmitChanges();
           return true;
       }

Open in new window

0
 
LVL 1

Author Comment

by:crcsupport
ID: 24044755
it is as simple as that:) Thank you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on link 14 48
How to add <appSettings> to the webconfig file 2 27
How useful is the free version of Selenium? 3 38
compare between entities in entity framework 8 74
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question