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