zoukankan      html  css  js  c++  java
  • datatable 的基本操作

    DataTable myTable=DS.Tables["表名"];     --->添加
      DataRow myNewRow=myTable.NewRow();
      myNewRow["你要添加的列名"]="";
      myNewRow["你要添加的列名"]="";
      myTable.Rows.Add(myNewRow);
      dg2.DataSource=myTable.DefaultView;
      dg2.DataBind(); //将新添的数据邦定


    DataRow[] myNewRow2=myTable.Select("id_jldw=11 AND name_jldw='内容'");   ----->修改
      //myNewRow2[0]["要修改的列名"]=值;
      myNewRow2[0]["要修改的列名"]=值;
      myNewRow2[0]["要修改的列名"]=值;
      dg3.DataSource=myTable.DefaultView;
      dg3.DataBind();//将新添的数据邦定



       myTable.Rows[0].Delete();//删除第一行             ---->删除
      dg4.DataSource=myTable.DefaultView;
      dg4.DataBind();
     protected void Button1_Click(object sender, EventArgs e)
        {

            string getname = this.DropDownList1.SelectedItem.Text.ToString();
            string getcode = this.DropDownList1.SelectedItem.Value.ToString();

            if (ViewState["ptable"] == null)
            {
                pipetable = new DataTable();
                pipetable.Columns.Add(new DataColumn("pid"typeof(int)));
                pipetable.Columns.Add(new DataColumn("pname"typeof(string)));
                DataColumn column = new DataColumn();
                column.ColumnName = "ID";
                column.AutoIncrement = true;
                column.AutoIncrementSeed = 1;
                column.AutoIncrementStep = 1;
                pipetable.Columns.Add(column);
                ViewState["ptable"] = pipetable;
            }
            else
            {
                pipetable = (DataTable)ViewState["ptable"];
            }

            DataRow[] myNewRow = pipetable.Select("pid='" + getcode + "'");
            if (myNewRow.Length.ToString() == "0")
            {
                DataRow row;
                row = pipetable.NewRow();
                row[0] = " " + getcode.ToString() + " ";
                row[1] = " " + getname.ToString() + " ";
                pipetable.Rows.Add(row);
            }
            BindGridView(pipetable);
            BindLine();
        }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            pipetable = (DataTable)ViewState["ptable"];
            pipetable.Rows[e.RowIndex].Delete();
            pipetable.AcceptChanges();
            BindGridView(pipetable);
            BindLine();
        }
     public void BindLine()
        { 
            DateTime dt = DateTime.Now;
            string DateFormats = Convert.ToDateTime(dt).ToString("yyyy-MM-dd");

            pipetable = (DataTable)ViewState["ptable"];
            string allpipes = "";
            if (pipetable.Rows.Count > 0)
            {
                for (int k = 0; k < pipetable.Rows.Count; k++)
                {
                    string  ppid = pipetable.Rows[k]["pid"].ToString();
                    allpipes += ppid + ",";
                    
                }

                allpipes = allpipes.TrimEnd(',');

                string sql1 = "select  PID,Pname from HeatLine where PID in (" + allpipes + ")  and convert(varchar(10),DateAndTime,120) = '" + DateFormats + "";
                DataSet ds1 = newdb.CommonDataSet(sql1);//取得所有管线

            }
        }
  • 相关阅读:
    Chrome 已经原生支持截图功能,还可以给节点截图!
    【promise| async/await】代码的控制力
    移动端各种分辨率手机屏幕----适配方法集锦
    Web Storage事件无法触发
    【php学习】图片处理三步走
    NYOJ 36 LCS(最长公共子序列)
    NYOJ 252 01串 普通dp
    NYOJ 18 The Triangle 填表法,普通dp
    NYOJ-171 聪明的kk 填表法 普通dp
    NYOJ17 最长单调递增子序列 线性dp
  • 原文地址:https://www.cnblogs.com/tiger8000/p/2235948.html
Copyright © 2011-2022 走看看