1

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

2 Answers 2

1

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"
Sign up to request clarification or add additional context in comments.

2 Comments

the 2nd one am having error, property access must assign to the property or use its value...
try table2.rows(0).item("Thursday") = 12345
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.