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

此语句用于使用存储过程插入数据。

如何在不使用存储过程但使用 LinqToSql 的情况下以相同的方式插入数据?

它的代码是什么?

4

3 回答 3

1
var db = new NorthwindDataContext();
// 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();
}
于 2012-12-17T16:24:04.390 回答
1

像这样的东西:

using(var context = new YourContext())
{
 var table1 = new table1(){ //fill out properties };
 context.table1.InsertOnSubmit(table1);
 context.SubmitChanges();
}
于 2012-12-17T16:25:01.693 回答
0

请参阅 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();
}
于 2012-12-17T16:24:24.467 回答