DataTable 和字符串数组之间进行转换

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace ChartFactorySpace { /// <summary> /// TableToArray 的摘要说明 /// </summary> public class TableToArray { public TableToArray() { // // TODO: 在此处添加构造函数逻辑 // } public static DataTable strArrayToTable(string[] strArray) { //数组 转 数据表DataTable DataTable dt = new DataTable(); dt.Columns.Add("name", typeof(string)); for (int i = 0; i < strArray.Length; i++) { DataRow dr = dt.NewRow(); dr["name"] = strArray[i]; dt.Rows.Add(dr); } return dt; } //数据表DataTable转数组 public static string[] TableTostrArray(DataTable dt, string columnname) { string[] arrayA = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr2 = dt.Rows[i]; arrayA[i] = Convert.ToString(dr2[columnname]); } return arrayA; } } }

你可能感兴趣的:(String,Class)