zoukankan      html  css  js  c++  java
  • DataTable.Select()使用

     DataTable dt = new DataTable();

            DataColumn dc = new DataColumn();
            dc.ColumnName = "ID";
            dc.DataType = Type.GetType("System.Int32");

            DataColumn dc2 = new DataColumn();
            dc2.ColumnName = "Name";
            dc2.DataType = Type.GetType("System.String");

            dt.Columns.Add(dc);
            dt.Columns.Add(dc2);

            DataRow dr = dt.NewRow();

            dr[0] = 1;
            dr[1] = "MJ";

            DataRow dr2 = dt.NewRow();
            dr2[0] = 2;
            dr2["Name"] = "LY";

            dt.Rows.Add(dr);
            dt.Rows.Add(dr2);

            GridView1.DataSource = dt;
            GridView1.DataBind();

            DataRow[] dr3 = dt.Select("Name='MJ'");

            DataTable dt2 = dt.Clone();

            /*DataColumn dc3 = new DataColumn();
            dc3.ColumnName = "ID";
            dc3.DataType = Type.GetType("System.Int32");

            DataColumn dc4 = new DataColumn();
            dc4.ColumnName = "Name";
            dc4.DataType = Type.GetType("System.String");

            dt2.Columns.Add(dc3);
            dt2.Columns.Add(dc4);*/


            for (int i=0;i<dr3.Length;i++)
            {
                dt2.ImportRow(dr3[i]);
            }

            if (dt2.Rows.Count > 0)
            {
                foreach (DataRow dr5 in dt2.Rows)
                {
                    Response.Write(dr5[0].ToString());
                }
            }

            GridView2.DataSource = dt2;
            GridView2.DataBind();

            Response.Write(dr3[0]["ID"].ToString());

  • 相关阅读:
    linux将命令添加到PATH中
    查看linux服务器时间
    spring参数校验及全局异常处理
    Https协议的工作过程
    反爬虫方式
    telnet进入某个端口后无法退出
    索引操作
    redis output buffer 设置太小导致oom
    mysql查询课程浏览记录表中最近一周浏览次数最多的课程
    C++ 读写注册表
  • 原文地址:https://www.cnblogs.com/VirtualMJ/p/628234.html
Copyright © 2011-2022 走看看