1. 方法一:
    2. DataTable  tblDatas = new DataTable("Datas");
    3. DataColumn dc = null;
    4. dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
    5. dc.AutoIncrement = true;//自动增加
    6. dc.AutoIncrementSeed = 1;//起始为1
    7. dc.AutoIncrementStep = 1;//步长为1
    8. dc.AllowDBNull = false;//
    9. dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
    10. dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
    11. dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
    12. DataRow newRow;
    13. newRow = tblDatas.NewRow();
    14. newRow["Product"] = "水果刀";
    15. newRow["Version"] = "2.0";
    16. newRow["Description"] = "打架专用";
    17. tblDatas.Rows.Add(newRow);
    18. newRow = tblDatas.NewRow();
    19. newRow["Product"] = "折叠凳";
    20. newRow["Version"] = "3.0";
    21. newRow["Description"] = "行走江湖七武器之一";
    22. tblDatas.Rows.Add(newRow);
    23. 方法二:
    24. DataTable tblDatas = new DataTable("Datas");
    25. tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
    26. tblDatas.Columns[0].AutoIncrement = true;
    27. tblDatas.Columns[0].AutoIncrementSeed = 1;
    28. tblDatas.Columns[0].AutoIncrementStep = 1;
    29. tblDatas.Columns.Add("Product", Type.GetType("System.String"));
    30. tblDatas.Columns.Add("Version", Type.GetType("System.String"));
    31. tblDatas.Columns.Add("Description", Type.GetType("System.String"));
    32. tblDatas.Rows.Add(new object[]{null,"a","b","c"});
    33. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    34. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    35. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    36. tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });

C# 向DataTable中插入数据或伪造DataTable的更多相关文章

  1. SqlBulkCopy将DataTable中的数据批量插入数据库中

    #region 使用SqlBulkCopy将DataTable中的数据批量插入数据库中 /// <summary> /// 注意:DataTable中的列需要与数据库表中的列完全一致.// ...

  2. list转datatable,SqlBulkCopy将DataTable中的数据批量插入数据库

    /// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...

  3. 第18课-数据库开发及ado.net 连接数据库.增.删.改向表中插入数据并且返回自动编号.SQLDataReade读取数据

    第18课-数据库开发及ado.net 连接数据库.增.删.改向表中插入数据并且返回自动编号.SQLDataReade读取数据 ADO.NET 为什么要学习? 我们要搭建一个平台(Web/Winform ...

  4. 使用C#向ACCESS中插入数据

    使用C#向ACCESS中插入数据   1.创建并打开一个OleDbConnection对象 string strConn = " Provider = Microsoft.Jet.OLEDB ...

  5. 触发器修改后保存之前的数据 表中插入数据时ID自动增长

    create or replace trigger t before update on test5 for each rowbegin insert into test55 values (:old ...

  6. Hive通过查询语句向表中插入数据注意事项

    最近在学习使用Hive(版本0.13.1)的过程中,发现了一些坑,它们或许是Hive提倡的比关系数据库更加自由的体现(同时引来一些问题),或许是一些bug.总而言之,这些都需要使用Hive的开发人员额 ...

  7. 向Oracle数据库中插入数据出错:ORA-01036 无效的变量名或数据

    向Oracle数据库中插入数据出错: 经过排查,因为Update数据时没有出错,所以OracleHelper没有问题: 看异常信息提示:无效的变量和数据,应该是SQL语句的问题,调试时所传的实例Use ...

  8. 解决getJdbcTemplate往oracle数据库中插入数据返回主键出错问题

    我们使用Spring中的JdbcDaoSupport往Mysql中插入数据并返回主键代码,我们使用的mysql数据库,主键在数据库中设置为自增长:该类继承自JdbcDaoSupport,所以能直接使用 ...

  9. Java程序在向mysql中插入数据的时候出现乱码

    今天在往数据库中插入数据的时候中文字符在数据库中就出现了乱码?网上有各种说法,但是适合我的,最终解决我的问题的只有下面一种! 在创建数据库的时候,注意设置编码方式. CREATE DATABASE ` ...

随机推荐

  1. ArcGIS Engine获得要素的中心点坐标

    IPoint centerPoint =new PointClass();//获得要素的中心点 IArea pArea = pFeature.Shape as IArea; pArea.QueryCe ...

  2. No WebApplicationContext found: no ContextLoaderListener registered?报错解决

    今天跑了下新搭的一个SSI框架. 报例如以下错误: 严重: Exception sending context initialized event to listener instance of cl ...

  3. 设置UITableViewCell高度的问题

    有非常多时候.UITableViewCell每行的高度是不固定的,须要动态设置. UITableView有个代理方法, -(CGFloat)tableView:(UITableView *)table ...

  4. 在iPad iOS8环境下打开相冊或者拍照

    在iPad下打开相冊或者拍照,假设使用 UIImagePickerController 打开相冊或者拍照,那必需要用到 UIPopoverController 去打开. UIPopoverContro ...

  5. ACM的算法分类 2015-04-16 14:25 22人阅读 评论(0) 收藏

    初期:  一.基本算法:        (1)枚举. (poj1753,poj2965)       (2)贪心(poj1328,poj2109,poj2586)       (3)递归和分治法.   ...

  6. 【Uva 10817】Headmaster's Headache

    [Link]: [Description] 一个学校,有s门课程(1<=s <=8),里面本身已经有m个老师了,然后还想招聘n个老师: 给出这m个老师和n个来应聘的老师的信息; (c[i] ...

  7. FZU 1096 QS Network

    QS Network Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original ID: ...

  8. swift 编译提前定义 --不知道怎么定义,可是能够#if

    var v:Int; #if _COND//不知道怎么定义.可是能够#if v = ; #else ; #endif println(v);//2

  9. [Python] Manipulate Data with Dictionaries in Python

    Dictionaries may be familiar to you as hash maps. In this lesson, you will learn how to create them, ...

  10. 转战Androidstudio之项目eclipse迁移

    新项目開始,决定转战as战场,(是应为听说了太多关于as的夸赞我才来的),期间各种不爽不适应历历在目啊.闲话少说,项目迁移開始 1.Eclipse迁出 当然直接从Eclipse迁出是有条件的,ADT必 ...