English 中文(简体)
利用LINQ更新记录清单
原标题:Update list of records using LINQ

我的网页上有一份编辑的GridView。 用户可以进入记录,在点击后,使用LINQ I将记录输入数据库。 它的工作是绝对的。

我无法说明如何更新记录。 一旦用户点击提交纽顿,我就把记录填入GridView。

如何做到这一点?

Dim db as new empDBDataContext
Dim rw As GridViewRow
Dim emp as new employee
emp.name="test"
emp.city="NYC"
emp.age=40
For each rw in GridView1.Rows
   Dim cert as new certifications
   cert.Name=CType(rw.FindControl("lblCert"), TextBox).Text
   cert.score=CType(rw.FindControl("lblScore"), TextBox).Text     
   emp.cert.add(cert)
Next

db.emp.insertonsubmit(emp)
db.submitChanges()
最佳回答

你可以使用你独特的认证身份识别器,从数据库中挑选浏览器(我使用<代码>lblId作为控制名称)。 然后,根据最新价值确定这些财产。 这与你为插入做些什么非常相似。 请原谅我的VB syntax无知......

For each rw in GridView1.Rows
 // Load the cert based on the ID of the row.
 Dim cert
 cert = (from c in db.certifications
        where c.Id = (int) CType(rw.FindControl("lblId"), TextBox).Text).Single()
 // Update the values.
 cert.Name=CType(rw.FindControl("lblCert"), TextBox).Text
 cert.score=CType(rw.FindControl("lblScore"), TextBox).Text
Next

// Submit all the changes.
db.submitChanges()
问题回答

暂无回答




相关问题
IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....

linq query for tag system - search for multiple tags

I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

How to filter duplicate list items

i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...

C# Grouping/Sorting a Generic List<> using LINQ

Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...

热门标签