Solved

rename Datatable column names

Posted on 2013-05-15
6
398 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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