#region=====建表=====
DataSet dataSet;
// 创建表
DataTable table = new DataTable("testTable");
private void testTable()
{
//声明列 行
DataColumn column;
DataRow row; // 创建主要列
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "Id";
column.ReadOnly = true;
column.Unique = true;
table.Columns.Add(column); // 创建字符串型的列
string[] colStr = new string[] { "FullName", "Code", "Department", "Manager", "Mobile", "Status", "ImgPath" };
foreach (string s in colStr)
{
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = s;
column.AutoIncrement = false;
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
} // 创建时间型的列
string[] colDate = new string[] { "StartDate", "PlanEndDate" };
foreach (string s in colDate)
{
column = new DataColumn();
column.DataType = System.Type.GetType("System.DateTime");
column.ColumnName = s;
column.AutoIncrement = false;
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
} //Id 列作为主键
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["Id"];
table.PrimaryKey = PrimaryKeyColumns; dataSet = new DataSet();
dataSet.Tables.Add(table); for (int i = 1; i <= 5; i++)
{
row = table.NewRow();
row["Id"] = i;
foreach (string s in colStr)
{ if (s == "ImgPath")
{
row[s] = "Img/" + i + ".jpg";
}
else
{
row[s] = s + " - " + i;
}
}
foreach (string s in colDate)
{
row[s] = DateTime.Now;
}
table.Rows.Add(row);
}
}
#endregion

最新文章

  1. ASP.NET Core 之 Identity 入门(三)
  2. codeforces 258div2 B Sort the Array
  3. Xamarin iOS编写第一个应用程序创建工程
  4. PHP 加密的几种方式
  5. [Everyday Mathematics]20150203
  6. 理解TCP可靠的通信
  7. 账户管理groupadd groupmod groupdel usermod usermod userdel
  8. hdu Co-prime
  9. C#list泛型集合
  10. HTML5 总结-Web存储-7
  11. SQL data reader reading data performance test
  12. SQL语句学习
  13. 更改Qt Application为 Qt Console Application
  14. 解决 win10 由于磁盘缓慢造成机器迟钝
  15. 关于HTTP的笔记
  16. 织梦dedeCMS数据库结构字段说明-简略说明
  17. ASP.NET AJAX入门系列(8):自定义异常处理
  18. spark shuffle 机制
  19. 读书--编写高质量代码 改善C#程序的157个建议
  20. 实例直观解释sessionid的作用

热门文章

  1. sublime3跳转函数
  2. Linux 解决E: Sub-process /usr/bin/dpkg returned an error code (1)错误
  3. 116-基于5VLX110T FPGA FMC接口功能验证6U CPCI平台 光纤PCIe卡
  4. 动态路由协议RIP
  5. Python小技巧:使用*解包和itertools.product()求笛卡尔积(转)
  6. MacOS Mojave 安装sshpass
  7. mobilenetV3
  8. Pycharm中Matplotlib图像不在弹出独立的显示窗口
  9. 《SaltStack技术入门与实践》——执行结果处理
  10. HBase过滤器(转载)