DataTable中 创建新列和给列赋值方法

        DataTable中 创建新列和给列赋值方法

 

 

 

        /// <summary>
        /// DataTable中 创建新列和给列赋值方法
        /// </summary>
        public void AddColumnTest()
        {
            //创建新列赋值
            DataSet dataSet = new DataSet();
            DataTable table = new DataTable();
            table.Columns.Add("新列1", typeof(Int32));
            table.Columns.Add("新列2", typeof(string));
            for (int i = 0; i < 10; i++)
            {
                DataRow row = table.NewRow();
                row["新列1"] = i.ToString() + "第一列";
                row["新列2"] = i.ToString() + "第二列";
            }
            dataSet.Tables.Add(table);
            //已有列赋值方式
            for (int j = 0; j < table.Rows.Count; j++)
            {
                table.Rows[j]["新列1"] = j.ToString() + "第一列--二次赋值";
                table.Rows[j]["新列2"] = j.ToString() + "第二列--二次赋值";
            }
        }

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