Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. concatenating strings into one datagrid cell

concatenating strings into one datagrid cell

Scheduled Pinned Locked Moved Database
questioncsharpdatabasealgorithmstutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    falles01
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • F falles01

      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.

      A Offline
      A Offline
      astanton1978
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups