Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

LINQ TO SQL add new records (C#)

Posted on 2009-04-01
2
536 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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