concatenating strings into one datagrid cell
-
Hello if anyone can please give me just a tiny sample of how I'd do this, not just what to do I will be so grateful. Just so you know. I have been googling for days on this and I'm not sure what to do as I am still pretty new to c#. This is what I want to do. I have a dataset and datagrid(search results table) displaying results like this. Siann Skills1 Siann Skills2 Siann Skills3 I want it to show this Siann Skills1,Skills2,Skills3. I have my select statement, then I have created a new datacolumn as I was told to do as below. Now after that, what do I do? How do I get all the skills in one column. I know I have to concatenate, and I have tried searching the net, but I can't find anything useful. is there any possibility for an example? dgSearchResults.Columns.Add(new DataColumn("skills", GetType())); I then have my foreach. I need to put something in the foreach. foreach (DataSet1.EmpSkillsRow empskillsRow in empskillsDT.Rows) { } I was told on the C# forum to try here. I am not using sql 2005 so I can't use cte.
-
Hello if anyone can please give me just a tiny sample of how I'd do this, not just what to do I will be so grateful. Just so you know. I have been googling for days on this and I'm not sure what to do as I am still pretty new to c#. This is what I want to do. I have a dataset and datagrid(search results table) displaying results like this. Siann Skills1 Siann Skills2 Siann Skills3 I want it to show this Siann Skills1,Skills2,Skills3. I have my select statement, then I have created a new datacolumn as I was told to do as below. Now after that, what do I do? How do I get all the skills in one column. I know I have to concatenate, and I have tried searching the net, but I can't find anything useful. is there any possibility for an example? dgSearchResults.Columns.Add(new DataColumn("skills", GetType())); I then have my foreach. I need to put something in the foreach. foreach (DataSet1.EmpSkillsRow empskillsRow in empskillsDT.Rows) { } I was told on the C# forum to try here. I am not using sql 2005 so I can't use cte.
Thats retarded that they told you to ask here... Try this and forgive VB, I have been stuck in VB land for too long and can no longer do c# from memory.
Dim ds as New DataSet() 'substitute your data set Dim dt as DataTable = ds.Tables(0) 'substitute your data table Dim dr as DataRow Dim strColumnAValue as String = String.Empty Dim strColumnBValues as New StringBuilder() For Each dr in dt.Rows If (Convert.ToString(dr(0)) = strColumnAValue) Then 'we are working on the same user "Siann" in this case and will append values strColumnBValues.Append(Convert.ToString(dr(1)).Trim() & ",") Else 'You are working on a new person and not "Siann" If strColumnBValues.Length <> 0 Then 'there is a user/ skillset to write out strColumnBValue = strColumnBValue.Remove(strColumnBValue.ToString().LastIndexOf(","), 1) 'remove the last comma Console.Writeline("User: " & strColumnAValue & " - Skills: " & strColumnBValues.ToString()) 'write out the value strColumnBValues.Length = 0 'clear the string builder strColumnAValue = Convert.ToString(dr(0)) 'set the new column A Value strColumnBValues.Append(Convert.ToString(dr(1)).Trim() & ",") 'add the first value End If End If Next 'dr