我有一个使用以下内容填充的datagridvie:
private void txtStreet_Leave(object sender, EventArgs e)
{
DataClasses1DataContext db = new DataClasses1DataContext();
var groups = (from c in db.GetTable<locality>()
where c.Number.Contains(txtNum.Text)
&& c.street.Contains(txtStreet.Text)
select new { c.Number, c.street, c.LienNumber, c.LienType, c.Amount } );
dataGridView1.DataSource = groups;
}
然后,我需要能够多选符合我的条件的记录,然后将它们添加到表中。我已经开始使用下面的代码来做到这一点。我的问题是从选定的行中提取值,然后用这些行更新正确的表。使用列表是错误的路线吗?
public void btnAddLocs_Click(object sender, EventArgs e)
{
List<DataGridViewRow> rowCollection = new List<DataGridViewRow>();
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
DataClasses1DataContext db = new DataClasses1DataContext();
MuniLien newlien = new MuniLien();
newlien.CaseNumberKey = _owner.caseNumberKeyTextBox.Text;
newlien.LienAmt =
newlien.LienDate =
newlien.LienReason =
newlien.LienNumber =
db.MuniLiens.InsertOnSubmit(newlien);
db.SubmitChanges();
}
}