Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to sort schema data

Author  Topic 

parrot
Posting Yak Master

132 Posts

Posted - 2008-07-18 : 00:56:09
I am extracting the names of fields from a table using the INFORMATION_SCHEMA table. My code is shown below:

string strSQL = "SELECT * FROM Mytable";
OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
da.FillSchema(ds, SchemaType.Source, "Mytable");
DataTable ft = ds.Tables["Mytable"];

My question is - how does one sort this so that my fields are in alphabetical order? Now the data is returned in the order in which the fields are aligned on the database. I tried to use the DataView sort as follows:
DataView dv = new DataView(ft, null,"columnFromName", DataViewRowState.CurrentRows);

I get an error saying I have an incorrect sort field. How do I find out the name of the sort field from the above query or how can I sort the data?
Dave

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-18 : 02:40:34
make use of INFORMATION_SCHEMA.COLUMNS


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -