Click here to Skip to main content
15,914,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show details comma separated on looping. I am getting datas with comma at the end if there are multiple ones.

What I have tried:

foreach (DataColumn dc in Source.Columns)
                  {
                      if (ds.Tables.Count > 0)
                      {
                          if (ds.Tables[1].Rows.Count > 0)
                          {
                              if (ds.Tables[1].Rows[0]["COLUMN_NAME"].ToString() != dc.ColumnName)
                              {
                                  if(string.IsNullOrEmpty(ColumnName)==false)
                                  {
                                      ColumnName = dc.ColumnName;
                                  }
                                  else
                                  {
                                      ColumnName = ColumnName + ',';
                                  }

                              }
                          }
                      }
                      copy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
                  }
Posted
Updated 1-Mar-17 5:53am
Comments
Karthik_Mahalingam 1-Mar-17 2:48am    
not clear.
OriginalGriff 1-Mar-17 2:55am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

Don't know what you want to do, but this line is weird:
C#
ColumnName = ColumnName + ',';


When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2
As I understand your question you are left with an extra comma at the end of your string if you have more than one column to process. E.g.
"thing1, thing2, thing3,"
There are several ways to get rid of that comma, here are 3 of them:
C#
if (ColumnName.EndsWith(","))
         ColumnName = ColumnName.TrimEnd(',');
C#
if (ColumnName.EndsWith(","))
    ColumnName = ColumnName.Remove(ColumnName.Length - 1, 1);
C#
(ColumnName.EndsWith(","))
   ColumnName = ColumnName.Substring(0, ColumnName.Length - 1);
 
Share this answer
 

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