insert into table1 (Wicket, Run, Catch)
values (Wicket + 2, Run + 22, Catch + 5)
此語句用於使用存儲過程插入數據。使用LinqToSql插入
如何在不使用存儲過程但使用LinqToSql的情況下以相同方式插入數據?
它將代碼是什麼?
insert into table1 (Wicket, Run, Catch)
values (Wicket + 2, Run + 22, Catch + 5)
此語句用於使用存儲過程插入數據。使用LinqToSql插入
如何在不使用存儲過程但使用LinqToSql的情況下以相同方式插入數據?
它將代碼是什麼?
請參閱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();
}
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();
}
事情是這樣的:
using(var context = new YourContext())
{
var table1 = new table1(){ //fill out properties };
context.table1.InsertOnSubmit(table1);
context.SubmitChanges();
}