Click here to Skip to main content
11,709,529 members (48,511 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL LINQ Silverlight , +
I am using C# SilverLight to create an application where I whould like to insert data into a database table. How do I do this in Linq-to-SQL?

My database table:
http://bildr.no/view/1412875[^]

My code:
/// <summary>
/// GetAllCarts
/// Sends all carts in database to list
/// </summary>
[OperationContract]
List<Lloyds_Cart> GetAllCarts()
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();
 
    var res = from carts in context.Lloyds_Carts select carts;
 
    return res.ToList();
 
}
/// <summary>
/// Create a new Cart
/// </summary>
[OperationContract]
void CreateCart()
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();
}
Posted 11-Mar-13 3:44am
Edited 11-Mar-13 4:32am
v2
Comments
sjelen at 11-Mar-13 10:20am
   
What have you tried? What is the problem?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try like this
context.Lloyds_Carts.InsertOnSubmit(Lloyds_Cart);
 
context.SubmitChanges();

Where Lloyds_Cart is the entity that you need to pass on the InsertOnSubmit method

Hope this helps
  Permalink  
Comments
Solo1233211 at 12-Mar-13 5:19am
   
[OperationContract]
void CreateCart()
{
PositionDataClassesDataContext context = new PositionDataClassesDataContext();

context.Lloyds_Carts.InsertOnSubmit(Lloyds_Cart);

context.SubmitChanges();

}

That does not work.
Jameel Moideen at 12-Mar-13 11:15am
   
What' the error showing?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

i want to know the actuall mapping coding

because mine is showing errors
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 8-May-13 15:37pm
   
You should not post such content as "answer".
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 590
1 OriginalGriff 250
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,027
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100