如何与价值的现有数据表添加新列?数据表、价值

由网友(骑白猪的王子)分享简介:我有一个数据表5列和10行。现在我想添加一个新列的数据表,我想为DropDownList值赋给新列。所以DropDownList的值应加10倍到新列。如何做到这一点?注意:如果不使用FOR循环I have One DataTable with 5 Columns and 10 Rows.Now I want to...

我有一个数据表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);
阅读全文

相关推荐

最新文章