Solved

rename Datatable column names

Posted on 2013-05-15
6
395 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now