• 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);//取得所有管线

            }
        }
  • 相关阅读:
    10 个让人惊讶的 jQuery 插件
    URL编码方法比较
    Java大文件分片上传/多线程上传源码
    Java大文件分片上传/多线程上传代码
    Java大文件分片上传/多线程上传插件
    Java大文件分片上传/多线程上传控件
    python函数
    关于言谈
    Sql语句之select 5种查询
    openstack之网络基础
  • 原文地址:https://www.cnblogs.com/tiger8000/p/2235948.html
Copyright © 2020-2023  润新知