MARKAND Bhatt MARKAND Bhatt - 1 month ago 17
ASP.NET (C#) Question

insert using LinqToSql

insert into table1 (Wicket, Run, Catch)
values (Wicket + 2, Run + 22, Catch + 5)


This statement is used to insert data using a stored procedure.

How can I insert data same way without using stored procedure but using LinqToSql?

What will be code for it?

Answer

See MSDN: http://msdn.microsoft.com/en-us/library/bb386941.aspx

// Create a new Order object.
Order ord = new Order
{
    OrderID = 12000,
    ShipCity = "Seattle",
    OrderDate = DateTime.Now
    // …
};

// Add the new object to the Orders collection.
db.Orders.InsertOnSubmit(ord);

// Submit the change to the database.
try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Make some adjustments.
    // ...
    // Try again.
    db.SubmitChanges();
}