Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

rename Datatable column names

Posted on 2013-05-15
6
Medium Priority
?
637 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 total points
ID: 39195439
Did you try

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 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