Linq to DataTable 操作

来源:互联网 发布:京东全球购奶粉 知乎 编辑:程序博客网 时间:2024/04/30 16:38
--- 绑定显示列表  
 private void BindList()
        {
            DataTable dt = dal.GetList("");   // GetList("") 方法从数据库读取并返回DataTable对象集合
            string args = "";     //查询参数
            if (!string.IsNullOrEmpty(this.txtvalue.Text))   // 判断文本框输入查询条件
            {
                args = this.txtvalue.Text.ToString();
            }
            var vdt = from temp in dt.AsEnumerable()      // linq语句  
                      where temp["CompanyName"].ToString().StartsWith(args)
                      select new
                      {  // 集合列表Eval()方法绑定的显示字段;
                          Comid = temp["Comid"].ToString(),
                          CompanyName = temp["CompanyName"].ToString(),
                          NCID = temp["NCID"].ToString(),
                          CreateDate = temp["CreateDate"].ToString(),
                          Phone = temp["Phone"].ToString()
                      };
            this.Repeater1.DataSource = vdt;
            this.Repeater1.DataBind();
        }
----以上的操作完全在aspx.cs的前台页面中的后台页面中书写的,但我不清楚到底在前台写linq绑定号还是在 dal数据层写好.欢迎各位dX歇息
0 0
原创粉丝点击