Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, help me please! I want to rename all columns names in datatable.But my code don't working.
C#
   bool o = true;
                foreach (DataTable table in _dataset.Tables)
                {  
                      foreach (DataColumn col in table.Columns)
                    {
                        if (!o)
                            break;
                        foreach (Columns_temp column in edit_WINDOW.Data)
                        {
                           if (col.ColumnName != column.column_title)
                            {
col.ColumnName = column.column_title.ToString();
                                o = false;
                                break;
                            }
                           else
                           {
                                col.ColumnName = column.column_title.ToString();
                            }
                        }
                //        o = false;
                    }
                }
Posted
Comments
Maciej Los 27-Sep-13 2:07am    
"Don't working" - do you think we can read in your mind?
Please, be more specific and provide more details.

1 solution

you should have to rename column one by one as like below example
C#
oDataSet.Tables[0].Columns["OldColumnName"].ColumnName = "NewColumnName";
 
Share this answer
 
v2

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