zoukankan      html  css  js  c++  java
  • linq

    1. IList<city> cc = new List<city> { new city { Name = "100", DistanceFromSeattle = 10, Country = "中国" }, new city { Name = "10", DistanceFromSeattle = 20, Country = "美国" } };          
                GridView1.DataSource = from p in cc  where p.DistanceFromSeattle>10 orderby p.DistanceFromSeattle descending select p; // aa.getData().Tables[0];
                
               GridView1.DataBind();

    2. DataClasses1DataContext dc = new DataClasses1DataContext();
                GridView1.DataSource = from p in dc.dnt_users where p.username.Length > 5 orderby p.username descending select p;
                GridView1.DataBind(); 

       或者GridView1.DataSource = dc.dnt_users .Where(p=>p.username.Length > 5);
             GridView1.DataBind(); 


       表关联   GridView1.DataSource = from p in dc.dnt_helps
                                       join m in dc.dnt_postids
                                       on p.pid equals m.pid
                                       select new
                                       { p.message, p.id, p.title, m.postdatetime };
                GridView1.DataBind();

    3. 存储过程EmployeeDataContext edc = new EmployeeDataContext();
                string firstname = "alice";
                string lastname = "wange";
                this.GridView1.DataSource = edc.ProcInsertEmployee(lastname, firstname);
                //edc.ProcInsertEmployeeResult("alice", "wang");
                this.GridView1.DataBind();

    4.添删改操作
         DataClasses1DataContext dc = new DataClasses1DataContext();

    添加 dnt_help dp = new dnt_help(); //表dnt_help
                dp.title = "10";
                dp.message = "中国";
                dp.pid = 10;
                dp.orderby = 1;
                dc.dnt_helps.InsertOnSubmit(dp); //插入
                dc.SubmitChanges();              //提交
                BindAll(); //绑定函数

    修改 var zz = from p in dc.dnt_helps where p.title == "10" select p;
                foreach (dnt_help dh in zz)
                {
                    dh.title = "china";
                }
                dc.SubmitChanges();
                BindAll();

    删除 var zz = from p in dc.dnt_helps where p.title == "china" select p;
                if (zz.Count<dnt_help>() > 0)
                {  
                    dc.dnt_helps.DeleteOnSubmit(zz.First<dnt_help>()); (1)
                    dc.SubmitChanges();  (2)
                    BindAll();
                }  //批量删除需要自己做扩展,要么循环(1)+(2),还有就是做存储过程
  • 相关阅读:
    IOS 两种控制器的使用,纯代码UITabBarController 与 UINavigationController
    iOS UI控件总结(全)
    IOS 参数string 转成url
    CocoaPods 的使用与一些异常情况的处理
    创建自己的 FrameWork(含demo)-Xcode7环境
    UITextView 一些属性的设置
    跳转第二弹
    iOS--登录注册页面-趣享-接口设计
    《大道至简》第一章阅读笔记
    软件工程个人作业02
  • 原文地址:https://www.cnblogs.com/yuanws/p/1130897.html
Copyright © 2011-2022 走看看