zoukankan      html  css  js  c++  java
  • C# 向DataTable中插入数据或伪造DataTable

      1. 方法一:  
      2.   
      3. DataTable  tblDatas = new DataTable("Datas");  
      4. DataColumn dc = null;  
      5. dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));  
      6. dc.AutoIncrement = true;//自动增加  
      7. dc.AutoIncrementSeed = 1;//起始为1  
      8. dc.AutoIncrementStep = 1;//步长为1  
      9. dc.AllowDBNull = false;//  
      10.   
      11. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));  
      12. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));  
      13. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));  
      14.   
      15. DataRow newRow;  
      16. newRow = tblDatas.NewRow();  
      17. newRow["Product"] = "水果刀";  
      18. newRow["Version"] = "2.0";  
      19. newRow["Description"] = "打架专用";  
      20. tblDatas.Rows.Add(newRow);  
      21.   
      22. newRow = tblDatas.NewRow();  
      23. newRow["Product"] = "折叠凳";  
      24. newRow["Version"] = "3.0";  
      25. newRow["Description"] = "行走江湖七武器之一";  
      26. tblDatas.Rows.Add(newRow);  
      27.   
      28. 方法二:  
      29.   
      30.  DataTable tblDatas = new DataTable("Datas");  
      31. tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));  
      32. tblDatas.Columns[0].AutoIncrement = true;  
      33. tblDatas.Columns[0].AutoIncrementSeed = 1;  
      34. tblDatas.Columns[0].AutoIncrementStep = 1;  
      35.   
      36. tblDatas.Columns.Add("Product", Type.GetType("System.String"));  
      37. tblDatas.Columns.Add("Version", Type.GetType("System.String"));  
      38. tblDatas.Columns.Add("Description", Type.GetType("System.String"));  
      39.   
      40. tblDatas.Rows.Add(new object[]{null,"a","b","c"});  
      41. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });  
      42. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });  
      43. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });  
      44. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" }); 
  • 相关阅读:
    使用spine骨骼动画制作的libgdx游戏
    【翻译】针对多种设备定制Ext JS 5应用程序
    【翻译】Ext JS最新技巧——2015-1-2
    Libgdx1.5.3发布
    Solr创建Core的两种方法
    Solr 7.7.0 部署到Tomcat
    CentOS7下安装JDK详细过程
    Linux常用命令总结
    Redis protected-mode属性解读
    使用RedisDesktopManager工具,解决连接失败问题
  • 原文地址:https://www.cnblogs.com/shouyeren/p/6639351.html
Copyright © 2011-2022 走看看