Solved

LINQ TO SQL add new records (C#)

Posted on 2009-04-01
2
527 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
Comment Utility
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
Comment Utility
it is as simple as that:) Thank you
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now