将数据添加到一个新的列 [英] adding data to a new column

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

问题描述

我有这样的一个表:

 周一周二周三周四
   15 4
 

这是通过使用下面的code完成的:

 暗淡FIELD3 = row.Field(中的Int32)(数据)
        昏暗字段1 = row.Field(串)(数据1)

        如果FIELD3 = 15然后

            如果字段1 =4区然后
            结束如果
            table2.Rows.Add(场,字段1)

        结束如果

    下一个
 

现在,如果我想补充一些数据,周三和周四使用相同的方法,它不会让我,它只会增加它在周一和周二,我如何能够将数据添加到星期三和星期四,当我调试有4列;周一 - 至周四但我怎么设置数据,周三和周四

我的专栏:

 昏暗表2作为新数据表

    列中的数据表。
    table2.Columns.Add(星期一,System.Type.GetType(System.String))
    table2.Columns.Add(星期二,System.Type.GetType(System.String))
    table2.Columns.Add(星期三,System.Type.GetType(System.String))
    table2.Columns.Add(星期四,System.Type.GetType(System.Int32的))
 

解决方案

您有几个选项。

table2.Rows.Add(场,字段1)设置在一行FIELD3和FIELD1数据的前两列。

您可以扩大该方法 table2.Rows.Add(场,字段1,价值列3,column4)需要。

您可以创建一个新的行,然后按列根据需要设置值列。

  table2.Rows(0).Item(星期四)= 12345
table2.Rows(0).Item(星期三)=我们踏踏实实周三
 

i have a table like this:

 Monday   Tuesday   Wednesday   Thursday
   15        4

this was done by using the code below:

        Dim field3 = row.Field(Of Int32)("data")
        Dim field1 = row.Field(Of String)("data1")

        If field3 = 15 Then

            If field1 = "Zone 4" Then
            End If
            table2.Rows.Add(field3, field1)

        End If

    Next

now if i want to add some data in wed and thurs using the same method, it wont let me, it will just add it under Monday and Tuesday, how would i able to add data to wed and thurs, when i debug, there are 4 columns; mon - thurs. but how do i set data to wed and thurs.

my columns:

    Dim table2 As New DataTable

    ' columns in the DataTable.
    table2.Columns.Add("Monday", System.Type.GetType("System.String"))
    table2.Columns.Add("Tuesday", System.Type.GetType("System.String"))
    table2.Columns.Add("Wednesday", System.Type.GetType("System.String"))
    table2.Columns.Add("Thursday", System.Type.GetType("System.Int32"))

解决方案

You have a few options.

table2.Rows.Add(field3, field1) sets the first two columns in your row with field3 and field1 as data.

You can expand this method table2.Rows.Add(field3, field1, "Value for column 3", "column4") as needed.

OR

You can create a new row, and then set the values column by column as needed.

table2.Rows(0).Item("Thursday") = 12345
table2.Rows(0).Item("Wednesday") = "We get down on wednesday"

这篇关于将数据添加到一个新的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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