• c# datatable


      
    
    DataTable dt = new DataTable("cart");   //创建表
    
    dt.Columns.Add( new DataColumn("number", Type.GetType("System.String")));   //创建列
    dt.Columns.Add( new DataColumn("qq", Type.GetType("System.String")));
    
    DataRow dr = dt.NewRow();   //创建行
    
    dr["number"]="123"        //行赋值
    dr["qq"]="1x"
    
    dt.Rows.Add(dr);          //添加行
    
    DataColumn[] clos = new DataColumn[1];   //设置主键 
    clos[0] = dt.Columns["number"];
    dt.PrimaryKey = clos;
    
    dt.Rows.Count             //表行数
    dt.Columns.Count          //表列数
    
    dtSource.Columns.Remove("qq");  //删除列
    
    DataRow dr = qtSource.Rows.Find(dt.Rows[i]["number"].ToString());  //查询行
    
    var num = qtSource.Select("number like 'xx%'");    //模糊查询 
    
    dt.Columns[0].ColumnName    //字段名

     重复判断

     1  var query = from d in dt.AsEnumerable()
     2                             group d by new {t1= d.Field<string>("file1") } into g
     3                             where g.Count() >1
     4                             select new
     5                             {
     6                                 g.Key,
     7                             };
     8                 var heavy = query.Select(o=>o.Key.t1).ToList();
     9                 
    10                 if (heavy.Count>0)
    11                 {
    12                     resultMsg = string.Join(",", heavy.ToList()) + "有重复项目不能保存";
    13                 }
  • 相关阅读:
    Python基础07
    python基础06
    python基础05
    python基础04
    python基础03
    python基础02
    python组件之wtforms
    PythonWeb框架之Flask
    Linux下yum安装Redis
    在vuex的mutations中使用vue的小技巧
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/9923811.html
Copyright © 2020-2023  润新知