Access datatable columns

S

shapper

Hello.

I created a datatable and I am trying to assign it to a grid.

It works when I use:

.... = dtCollaborators.Columns(0).ToString()

But if I use

.... = dtCollaborators.Columns(1).ToString()

Or

.... = dtCollaborators.Columns("Mobile").ToString()

Any idea why?

I create my DataTable as follows:

Public Shared Function Collaborators() As DataTable

' Create collaborators data table
Dim dtCollaborators As New DataTable

' Add columns to collaborators data table
With dtCollaborators.Columns
.Add(New DataColumn("Name", GetType(String)))
.Add(New DataColumn("Mobile", GetType(String)))
.Add(New DataColumn("Email", GetType(String)))
.Add(New DataColumn("City", GetType(String)))
End With

' Create and add a new collaborator row
Dim drRow01 As DataRow
drRow01 = dtCollaborators.NewRow

' Define collaborator row values
drRow01("Name") = "John"
drRow01("Mobile") = "983498223"
drRow01("Email") = "(e-mail address removed)"
drRow01("City") = "New York"

' Add row to collaborators data table
dtCollaborators.Rows.Add(drRow01)

' Create and add a new collaborator row
Dim drRow02 As DataRow
drRow02 = dtCollaborators.NewRow

' Define collaborator row values
drRow02("Name") = "Andrew"
drRow02("Mobile") = "983498223"
drRow02("Email") = "(e-mail address removed)"
drRow02("City") = "Paris"

' Add row to collaborators data table
dtCollaborators.Rows.Add(drRow02)

' Return collaborators data table
Return dtCollaborators

End Function ' Collaborators


Thanks,

Miguel
 
T

Teemu Keiski

Can you post how do you assign it?

This

.... = dtCollaborators.Columns(0).ToString()

confuses me. Are you setting that into a GridView to a BoundField or
something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top