Entity_Framework的增删改查,以及绑定GridView和TreeView
来源:互联网 发布:淘宝发货清单表格 编辑:程序博客网 时间:2024/05/20 06:06
EF框架
1.EF的增删改查:
增加:
protected void SaveBtn_Click(object sender, EventArgs e) {
Model.Entities11 graphsx = new Model.Entities11();
Model.T_NET_GRAPH_SUB_MK graphEntity=new Model.T_NET_GRAPH_SUB_MK();
graphEntity.ID = TxtId.Text;
decimal width;
decimal.TryParse(TxtWidth.Text, out width);
graphEntity.WIDTH = width;
decimal heigh;
decimal.TryParse(TxtHeigh.Text, out heigh);
graphEntity.HEIGHT = heigh;
graphEntity.TITLE = TxtTitle.Text;
graphEntity.BB = TxtBb.Text;
graphsx.AddObject("T_NET_GRAPH_SUB_MK", graphEntity);
graphsx.SaveChanges();
GrvGraphBind();
}
关于GridView 的编辑和删除
protected void GrvGraph_RowCommand(object sender, GridViewCommandEventArgs e){
Model.Entities11 graphsx = new Model.Entities11();
if (e.CommandName == "Editorder"){
string id = e.CommandArgument.ToString();
Model.T_NET_GRAPH_SUB_MK graphEntity = graphsx.T_NET_GRAPH_SUB_MK.First<Model.T_NET_GRAPH_SUB_MK>(u => u.ID == id);
TxtId.Text = id;
TxtHeigh.Text = graphEntity.HEIGHT.ToString();
TxtWidth.Text = graphEntity.WIDTH.ToString();
TxtTitle.Text = graphEntity.TITLE;
TxtBb.Text = graphEntity.BB;
}
else if(e.CommandName == "Delorder") {
string id = e.CommandArgument.ToString();
Model.T_NET_GRAPH_SUB_MK graphEntity = graphsx.T_NET_GRAPH_SUB_MK.First<Model.T_NET_GRAPH_SUB_MK>(u => u.ID == id);
graphsx.DeleteObject(graphEntity);
graphsx.SaveChanges();
GrvGraphBind();
}
}
2.EF的绑定GridView 无条件绑定:
private void GrvGraphBind() {
var edm = new Model.Entities11();
GrvGraph.DataSource = edm.T_NET_GRAPH_SUB_MK;
GrvGraph.DataBind();
}
联合绑定:
LINQ:
private void GrvLhBind(){
var edm = new Model.Entities11();
var query = from sub in edm.T_NET_SUB_MK
from graph in edm.T_NET_GRAPH_SUB_MK
where sub.ID == graph.SUB_MK_ID
select new{ idmc = sub.TITLE, graph.SQL, graph.TITLE, graph.LABEL, graph.BB, graph.SUB_MK_ID };
GrvLh.DataSource = query;
GrvLh.DataBind();
}
根据条件绑定:
ESQL:
ObjectQuery<Model1.T_NET_GRAPH_SUB_MK> query = edm.CreateQuery<Model1.T_NET_GRAPH_SUB_MK>("select value c from T_NET_GRAPH_SUB_MK as c where c.sub_mk_id='ebb3b7ef-3c38-4116-bb11-0c9580cf02e1'");
LINQ:
Var edm= from c in customers where c.CustomerID == "ALFKI" select c;
1.EF的增删改查:
增加:
protected void SaveBtn_Click(object sender, EventArgs e) {
Model.Entities11 graphsx = new Model.Entities11();
Model.T_NET_GRAPH_SUB_MK graphEntity=new Model.T_NET_GRAPH_SUB_MK();
graphEntity.ID = TxtId.Text;
decimal width;
decimal.TryParse(TxtWidth.Text, out width);
graphEntity.WIDTH = width;
decimal heigh;
decimal.TryParse(TxtHeigh.Text, out heigh);
graphEntity.HEIGHT = heigh;
graphEntity.TITLE = TxtTitle.Text;
graphEntity.BB = TxtBb.Text;
graphsx.AddObject("T_NET_GRAPH_SUB_MK", graphEntity);
graphsx.SaveChanges();
GrvGraphBind();
}
关于GridView 的编辑和删除
protected void GrvGraph_RowCommand(object sender, GridViewCommandEventArgs e){
Model.Entities11 graphsx = new Model.Entities11();
if (e.CommandName == "Editorder"){
string id = e.CommandArgument.ToString();
Model.T_NET_GRAPH_SUB_MK graphEntity = graphsx.T_NET_GRAPH_SUB_MK.First<Model.T_NET_GRAPH_SUB_MK>(u => u.ID == id);
TxtId.Text = id;
TxtHeigh.Text = graphEntity.HEIGHT.ToString();
TxtWidth.Text = graphEntity.WIDTH.ToString();
TxtTitle.Text = graphEntity.TITLE;
TxtBb.Text = graphEntity.BB;
}
else if(e.CommandName == "Delorder") {
string id = e.CommandArgument.ToString();
Model.T_NET_GRAPH_SUB_MK graphEntity = graphsx.T_NET_GRAPH_SUB_MK.First<Model.T_NET_GRAPH_SUB_MK>(u => u.ID == id);
graphsx.DeleteObject(graphEntity);
graphsx.SaveChanges();
GrvGraphBind();
}
}
2.EF的绑定GridView 无条件绑定:
private void GrvGraphBind() {
var edm = new Model.Entities11();
GrvGraph.DataSource = edm.T_NET_GRAPH_SUB_MK;
GrvGraph.DataBind();
}
联合绑定:
LINQ:
private void GrvLhBind(){
var edm = new Model.Entities11();
var query = from sub in edm.T_NET_SUB_MK
from graph in edm.T_NET_GRAPH_SUB_MK
where sub.ID == graph.SUB_MK_ID
select new{ idmc = sub.TITLE, graph.SQL, graph.TITLE, graph.LABEL, graph.BB, graph.SUB_MK_ID };
GrvLh.DataSource = query;
GrvLh.DataBind();
}
根据条件绑定:
ESQL:
ObjectQuery<Model1.T_NET_GRAPH_SUB_MK> query = edm.CreateQuery<Model1.T_NET_GRAPH_SUB_MK>("select value c from T_NET_GRAPH_SUB_MK as c where c.sub_mk_id='ebb3b7ef-3c38-4116-bb11-0c9580cf02e1'");
LINQ:
Var edm= from c in customers where c.CustomerID == "ALFKI" select c;
- Entity_Framework的增删改查,以及绑定GridView和TreeView
- GridView 的增删改查
- GridView 增删改查
- GridView的增删改查的例子
- Webform GridView列表增删改查结合EF数据绑定
- GridView中常用的增删改查
- 含有dropdownlist的gridview增删改查
- 含有dropdownlist的gridview增删改查
- Hibernate实现增删改查以及和JDBC的关系
- solr的增删改查和高亮以及分组
- GridView绑定列增删改
- jqery easyui 利用treeview实现菜单的增删改查
- bootstrap treeview 增删改查 的正确姿势
- GridView控件增删改查(查)
- 基于Grove的在GridView上的增删改查
- gridview不分层的增删改查操作
- 网页链接Oracle实现数据的增删改查--gridview
- 文件和文件夹的增删改查
- 世界500强:公司面试:智力题集锦(附答案)
- HTTP协议POST请求问题总结
- 通过Spring进行远程服务访问
- 图像处理研究网站
- sql中函数
- Entity_Framework的增删改查,以及绑定GridView和TreeView
- GETIP信息分析
- java 写csv
- jQuery ajax应用
- Linux和Windows下的Tomcat JVM内存设置
- 基于mySql的JAVA分页自定义标签详解
- 【Android开发那点破事】定制返回按钮的动画效果。
- 头文件问题
- jQuery