It gives you a concatenated output because that's what you are asking it to do.
Instead of concatenating the columns, project columns in a new
anonymous type
.
Change your code as below:
var NameList = (from r in dataset.Tables["MyTableName"].AsEnumerable()
select new
{
Name = r.Field<string>("name"),
Age = r.Field<string>("age"),
Salary = r.Field<string>("salary"),
City = r.Field<string>("city")
});
This basically creates an anonymous type which is a collection having columns Name, Age, Salary and City. You can iterate through them using a foreach loop. Also remember that the query will execute only when the result collection will be iterated. Add ToList() in the end if you want to execute it at that very moment.
You
GridView
should accept anonymous type as
DataSource
. Just take care of the column names.
Hope that helps!