0
I am trying to do this


col1  col2  col3

a       1     b

a       2     c

a       3     d

changes to

col1 col2 col3

a    1   b, c, d

     2    

     3    

both col1 and col3 has text values

I wrote this code, what is wrong with this code? Anyone?

DataSet ds = new DataSet();

using (var mm = new OracleDataAdapter(objCmd))
            mm.Fill(ds, "TableName");
            objCmd.Dispose();

DataView dv = ds.Tables["TableName"].DefaultView;

DataTable dt = ds.Tables["SURVEY_MASTER"];

 IEnumerable<string> query = (from row in dt.AsEnumerable()
                              select row.Field<string>("Col1")).Distinct();

 this.GridView1.DataSource = query;

This code above is not working.......I am trying to change

either ds or datatable values and then to display it

in gridview

Whats wrong with the code?

Anyone have simple solution of what i am trying to achieve?

Please do write full code, if possible

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
user680865
  • 289
  • 2
  • 6
  • 13

2 Answers2

0

The task might be better handled at the SQL level. See this repost-of-a-repost which suggests using the COLLECT function and to concatenate row values into a string: How can I combine multiple rows into a comma-delimited list in Oracle?

Community
  • 1
  • 1
LesterDove
  • 3,014
  • 1
  • 23
  • 24
0

by aggregating it that way you are violating column 2 because "c","d" are not "1".

you should re-think your aggregation, or take out col2 from the equation.

this could be achieved using a group by

var groups = from v in values group v by col1 into gv select v

that way B,C,D will be in the single group.

Sonic Soul
  • 23,855
  • 37
  • 130
  • 196