Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to convert dataset to list(of string)?

Code:
VB
Dim name As String
      name = dsMatter.Tables(0).Rows(0).Item("FirstName")

It tried to change the code to:
VB
Dim name As String
      name = dsMatter.Tables(0).Rows(0).Item("FirstName").Tolist

But is not working.. Can you please help me with this?
Posted
Updated 10-Aug-15 9:51am
v2
Comments
F-ES Sitecore 10-Aug-15 10:29am    
A dataset has rows and columns, a List<string> only has columns so you'll need to explain what your list is going to look like as there is no one-to-one conversion.
apr1234 10-Aug-15 10:33am    
List looks like some what like this
FirstName
--------
Name1
PIEBALDconsult 10-Aug-15 10:51am    
If you don't want a DataSet, then don't ask for one. Construct the data in the form you want it in. "Converting" is a cry for help.

1 solution

Hi,

Have a look at an Introduction to LINQ in Visual Basic[^]

Then you can convert to a list of strings, by doing something like this:
VB
Dim sList As List(Of String) = dsMatter.Tables(0).AsEnumerable().[Select](Function(r) r.Field(Of String)("FirstName")).ToList()


... hope it helps.
 
Share this answer
 
v2
Comments
hypermellow 10-Aug-15 10:51am    
If you bring everything onto a single line it, the error should resolve.
... I've now updated my solution.

*Edit*
Re: Your error message: Have you imported the System.Linq Namespace?
apr1234 10-Aug-15 11:11am    
Got resolved.. I added.. Thanks!
Maciej Los 10-Aug-15 15:53pm    
5ed!
hypermellow 11-Aug-15 3:55am    
Thank You! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900