By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

Access datatable columns

P: n/a


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") = "jo**@mydomain.com"
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") = "an****@mydomain.com"
drRow02("City") = "Paris"

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

' Return collaborators data table
Return dtCollaborators

End Function ' Collaborators
Thanks,

Miguel

Feb 16 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"shapper" <md*****@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>

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") = "jo**@mydomain.com"
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") = "an****@mydomain.com"
drRow02("City") = "Paris"

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

' Return collaborators data table
Return dtCollaborators

End Function ' Collaborators
Thanks,

Miguel
Feb 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.