小弟用linq取出数据绑定到gridview控件上,代码如下:
CompanyTypeDataContext companyType = new CompanyTypeDataContext();
IEnumerable<fgf_qyxz> ct = companyType.fgf_qyxzs;
this.gv1.DataSource = ct;
this.gv1.DataBind();
但是,如果我想在gridview增加一行或多行怎么写呢?IEnumerable接口并没定义Add之类的方法啊?各位若用linq遇到此类问题是如何解决的?
参考以下代码
NorthwindDataContext db = new NorthwindDataContext();
var newCustomer = new Customer
{
CustomerID = "MCSFT",
CompanyName = "Microsoft",
ContactName = "John Doe",
ContactTitle = "Sales Manager",
Address = "1 Microsoft Way",
City = "Redmond",
Region = "WA",
PostalCode = "98052",
Country = "USA",
Phone = "(425) 555-1234",
Fax = null
};
db.Customers.InsertOnSubmit(newCustomer);
db.SubmitChanges();
IEnumerable接口并没定义Add之类的方法?
1.其实Beta2时的Add方法,已经变为InsertOnSubmit方法。
2.具体应用:调用InsertOnSubmit()方法来增加一条记录,并用SubmitChanges()将其持久化到数据库中。
3.参见以上小潘的代码。
4.还有一个InsertAllOnSubmit方法(那它和InsertOnSubmit其实做的一样事性,它们都是新增数据调用SubmitChanges提交到DataBase)