Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have query which retrieves columns from 4 tables using join statement.Now I want to store the column name or alias name of the field name of that query.please help me how to retrieve them?

Example If I have table called A,B,C which have columns like Aa,Ab,Ac,Ba,Bb,Bc,Ca,Cb Respectively then in join statement I`l retrieve Aa,Bb,Ca,Cb

Now I want to save Column name Aa,Bb,Ca,Cb
Posted
Updated 19-Aug-12 18:43pm
v3
Comments
_Amy 20-Aug-12 0:20am    
What is your result? DataTable or DataSet? Or some scalers?
Mukunda Raj 20-Aug-12 0:26am    
Example If I have table called A,B,C which have coloumns like Aa,Ab,Ac,Ba,Bb,Bc,Ca,Cb Respectively then in join statement I`l retrieve Aa,Bb,Ca,Cb

Now I want to save Coloumn name Aa,Bb,Ca,Cb

Hi,

If you are executing your query and your result is in form of DataSet the you can get each column name using DataColumn

Please check this[^] discussion, you can find your answer from there.

Let me know if you are not storing your query result in DataSet.

Good luck

Thanks
-Amit Gajjar
 
Share this answer
 
Comments
Mukunda Raj 20-Aug-12 1:45am    
In that discussion,what is ds,tables[0]?

DropDownList1.DataSource = ds.Tables[0].DefaultView;
AmitGajjar 20-Aug-12 1:53am    
ds is your DataSet.
Mukunda Raj 20-Aug-12 2:16am    
Thanks i found solution!!

string[] columnNames = dtGrid.Columns.Cast<datacolumn>().Select(x => x.ColumnName).ToArray();

This is what actually I was looking for.
AmitGajjar 20-Aug-12 2:26am    
Mark Solution as answered if it helps you, it will help others to know correct answer.
string[] columnNames = dtGrid.Columns.Cast<datacolumn>().Select(x => x.ColumnName).ToArray();
 
Share this answer
 
PLz Explain a little More , . Check For into in u query Plz Explain .
 
Share this answer
 
Comments
_Amy 20-Aug-12 0:22am    
This is not an answer. Please ask the your doubts in comments.
RAKESH CHAUBEY 20-Aug-12 0:30am    
k

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900