Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
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
Updated 11-Mar-13 4:32am
v2
Comments
sjelen 11-Mar-13 10:20am    
What have you tried? What is the problem?

Try like this
C#
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
 
Share this answer
 
Comments
Solo1233211 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 VM 12-Mar-13 11:15am    
What' the error showing?
 
Share this answer
 
i want to know the actuall mapping coding

because mine is showing errors
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900