Solved

rename Datatable column names

Posted on 2013-05-15
6
409 Views
Last Modified: 2013-06-11
Is there a way to rename column names in datatable and save it  in vb.net or C#?
0
Comment
Question by:VBdotnet2005
6 Comments
 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39168720
	   

 string strCreate = "EXEC sp_rename 'ExistingName', 'NewName'";

 SqlConnection conDatabase = new 
 SqlConnection("Data Source=(local);Database='Countries2';Integrated Security=yes");
	 SqlCommand    cmdDatabase = new SqlCommand(strCreate, conDatabase);

	conDatabase.Open();

	cmdDatabase.ExecuteNonQuery();

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 39168925
I am sorry, I get this Datatable from a session on my aspx page. I am wondering if I can rename column names.

Sample

From
Accountnumber      Address      ciy      state      zip

to
CustomerAccount      Customer_Address      Customer_ciy      Customer_state      Customer_zip
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 39170603
you can rename column name in Query like below.

select AccountNumber as CustomerAccount,Address As Customer_Address ,city as Customer_city, state as Customer_State,zip as Customer_Zip from TableName.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39170912
>and save it  in vb.net or C#?

Save back to database?
0
 

Author Comment

by:VBdotnet2005
ID: 39189460
No update datatable with new columns names.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39195439
Did you try

dTable.Columns(index).Caption = "MyColumn"
?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question