如何与价值的现有数据表添加新列? [英] How to add New Column with Value to the Existing DataTable?

查看:159
本文介绍了如何与价值的现有数据表添加新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表5列和10行。      现在我想添加一个新列的数据表,我想为DropDownList值赋给新列。      所以DropDownList的值应加10倍到新列。      如何做到这一点? 注意:如果不使用FOR循环

I have One DataTable with 5 Columns and 10 Rows. Now I want to add one New Column to the DataTable and I want to assign DropDownList value to the New Column. So the DropDownList value should be added 10 times to the New Column. How to do this? Note: Without using FOR LOOP.

例如:我现有的数据表是这样的。

For Example: My Existing DataTable is like this.

   ID             Value
  -----          -------
    1              100
    2              150

现在我想添加一个新列CourseID这个数据表。 我有一个DropDownList的。其选定的值是1。 所以,我现有的表应该有如下:

Now I want to add one New Column "CourseID" to this DataTable. I have One DropDownList. Its selected value is 1. So My Existing Table should be like below:

    ID              Value         CourseID
   -----            ------       ----------
    1                100             1
    2                150             1

如何做到这一点?

How to do this?

推荐答案

没有For循环:

Dim newColumn As New Data.DataColumn("Foo", GetType(System.String))     
newColumn.DefaultValue = "Your DropDownList value" 
table.Columns.Add(newColumn) 

这是未经测试。我用了一个网上的C#转换工具

This is untested. I used an online C# conversion tool:

System.Data.DataColumn newColumn = new System.Data.DataColumn("Foo", typeof(System.String));
newColumn.DefaultValue = "Your DropDownList value";
table.Columns.Add(newColumn);

这篇关于如何与价值的现有数据表添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆