创建数据表

来源:互联网 发布:天津大学数据库 编辑:程序博客网 时间:2024/06/04 18:35
#region 创建数据表    public static DataTable CreateTable(string[] strColumns, string[] strRows)
       /// <summary>
       /// 创建数据表
       /// </summary>
       /// <param name="strColumns">列名数组</param>
       /// <param name="strRows">行数据数组</param>
       /// <returns>返回结果的数据表</returns>
       public static DataTable CreateTable(string[] strColumns, string[] strRows)
       {
           DataTable dt = new DataTable();
           if (strColumns.Length > 0)
           {
               for (int i = 0; i < strColumns.Length; i++)
               {
                   dt.Columns.Add(strColumns[i], typeof(string));
               }


               if (strRows.Length > 0)
               {
                   DataRow[] dr = new DataRow[strRows.Length];
                   for (int k = 0; k < strRows.Length; k++)
                   {
                       dr[k] = dt.NewRow();
                       for (int i = 0; i < strColumns.Length; i++)
                       {
                           dr[k][i] = strRows[k];
                       }
                       dt.Rows.Add(dr[k]);


                   }
               }
           }


           return dt;
       } 
       #endregion
0 0