zoukankan      html  css  js  c++  java
  • C# 在代码中创建 DataTable 和从数据库取出的数据 DataTable

    private void MakeDataTableAndDisplay(){
       // Create new DataTable.
       DataTable myDataTable = new DataTable("MyDataTable");
      
       // Declare DataColumn and DataRow variables.
       DataColumn myDataColumn;
       DataRow myDataRow;

       // Create new DataColumn, set DataType, ColumnName and add to DataTable.   
       myDataColumn = new DataColumn();
       myDataColumn.DataType = System.Type.GetType("System.Int32");
       myDataColumn.ColumnName = "id";
       myDataTable.Columns.Add(myDataColumn);

       // Create second column.
       myDataColumn = new DataColumn();
       myDataColumn.DataType = Type.GetType("System.String");
       myDataColumn.ColumnName = "item";
       myDataTable.Columns.Add(myDataColumn);


       // Create new DataRow objects and add to DataTable.   
       for(int i = 0; i < 10; i++){
          myDataRow = myDataTable.NewRow();
          myDataRow["id"] = i;
          myDataRow["item"] = "item " + i;
          myDataTable.Rows.Add(myDataRow);
       }
       // Set to DataGrid.DataSource property to the table.
       dataGrid1.DataSource = myDataTable;
    }

    --------------------
    C# 在代码中创建 DataTable 和从数据库取出的数据 DataTable 合并
          myDataRow = myDataTable.NewRow();
          myDataRow["id"] = i;
          myDataRow["item"] = "item " + i;
          myDataTable.Rows.Add(myDataRow);

  • 相关阅读:
    稀疏矩阵解题数学库 -- UMFPACK
    国外程序猿整理的C++大全
    SQL实用语句大全
    this 三句话
    ELK 7.4.2 单机安装配置
    简单搭建DNS服务器——bind
    关于博客皮肤
    Golang 实现 array_push
    Golang 发送POST请求,加header头,带参数
    Golang 签名
  • 原文地址:https://www.cnblogs.com/beeone/p/2010784.html
Copyright © 2011-2022 走看看