m ali
m ali

Reputation: 646

adding data to a new column

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"))

Upvotes: 1

Views: 99

Answers (2)

ginman
ginman

Reputation: 1315

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"

Upvotes: 1

Chase Ernst
Chase Ernst

Reputation: 1155

You can go about using an SQL statement also, that may make things a little easier on yourself. There are many sites to learn the differnet SQL statements w3schools is great.

Upvotes: 0

Related Questions