Solved

rename Datatable column names

Posted on 2013-05-15
6
394 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now