使用Linq的目的是为了保存大文本
https://blog.csdn.net/weixin_30536513/article/details/97600630
这段代码应该是更新操作
FlowDataContext DCDC = new FlowDataContext();//数据上下文
Config ce = new Config();//表格
try
{
//ConfigID.Text是添加页面的隐藏字段
ce = DCDC.Config.Single(p => p.ID.Equals(ConfigID.Text));
ce.FlowType = DDl1.SelectedValue;
ce.FlowName = TFlowName.Text;
ce.FlowCode=TFlowCode.Text;
ce.Remark = TRemark.Text;
一旦调用 SubmitChanges() 就将这些改变保存到数据库中去。
DCDC.SubmitChanges();
Window1.Hidden = true;
BindGrid1();
}
catch
{
添加数据到数据库中
Flow.Config表中的ID应该是Guid.NewGuid();
System.Guid guid = new Guid();
guid = Guid.NewGuid();
Config c = new Config();
c.ID = guid.ToString();
c.FlowName = TFlowName.Text;
c.FlowType = DDl1.SelectedValue;
c.FlowCode = TFlowCode.Text;
c.Remark = TRemark.Text;
DCDC.Config.InsertOnSubmit(c);
//保存到数据库
DCDC.SubmitChanges();
Window1.Hidden = true;
BindGrid1();
}
查询列表中的内容
if (KeyWord.Text.Length > 0)
{
FlowDataContext DCDC = new FlowDataContext();
var query = DCDC.Config.Where(fc => fc.FlowName.Contains(KeyWord.Text) || fc.FlowType.Contains(KeyWord.Text) ||
fc.FlowCode.Contains(KeyWord.Text));
//此段代码就是将json类型的数组,变成DataTable
return Govaze.Components.DataTableExtensions.ToDataTable(query);
}
else
{
FlowDataContext DCDC = new FlowDataContext();
var query = from fc in DCDC.Config
select fc;
return Govaze.Components.DataTableExtensions.ToDataTable(query);
}
//删除语句
FlowDataContext DC = new FlowDataContext();
Config fc = new Config();
fc = DC.Config.Single(p => p.ID.Equals(Grid1.DataKeys[e.RowIndex][0].ToString()));
foreach (Branch bh in fc.Branch)
{
foreach (Branch_Charge bc in bh.Branch_Charge)
{
DC.GetTable<Branch_Charge>().DeleteOnSubmit(bc);
}
DC.GetTable<Branch>().DeleteOnSubmit(bh);
}
DC.GetTable<Config>().DeleteOnSubmit(fc);
//提交到数据库的意思
DC.SubmitChanges();
BindGrid1();