zoukankan      html  css  js  c++  java
  • C# 内存建表备忘

    #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
  • 相关阅读:
    Linux
    前端
    第一章 初识 MyBatis
    mysql 复习
    五 、 Kafka producer 拦截器(interceptor) 和 六 、Kafka Streaming案例
    spark graphx图计算
    四、Kafka API 实战
    三、Kafka工作流程分析
    二、Kafka集群部署
    一、KafKa概述
  • 原文地址:https://www.cnblogs.com/Tirisfal/p/5581270.html
Copyright © 2011-2022 走看看