Order Tables Ascending in DataSet
Hey there, I have a problem cause I don't know how to order tables ascending within a dataset, so I need to know how can I do that, I have for example these tablenames within a dataset in this order:
"0050Colors"
"0021Cars"
"0120Symbols"
"1008Field"
"0215Country"
that's the order in what the tables are added into the dataset, and I need them in the next order:
"0021Cars"
"0050Colors"
"0120Symbols"
"0215Country"
"1008Field"
So what would be the code, to order the tables in that way, please help, thanks!!!.
[707 byte] By [
Ccercone] at [2007-12-21]
Is this SQLServer or Access? If it's Access could we see the table?
Well I get the tables from an access database and then I add those into the Dataset..
and about if we could see the tables, I don't know what do you mean?
the tables just have one column and within all the tables, the only column they have, has the same name.. hope this help!
and thanks for your help
WHat's the name of your table and the Column?
Well the names are those I gave you in the first message, within the dataset are like ten tables with the same format for tha table name I gave you before, something like this:
"0050Colors" first table added
"0021Cars" second table added
"0120Symbols" third table added
"1008Field" fourth table added
"0215Country" fifth table added
and I need them in the next order within the dataset:
"0021Cars" second table added before
"0050Colors" first table added before
"0120Symbols" third table added before
"0215Country" fifth table added before
"1008Field" fourth table added before
its something like shot the tables ascending::
and the column name is "ColumnPrimera" for all the tables within the dataset!!.
thanks!!.
whoops...
In order to have the order you want them you going to have to add them in that order.
Ohhh, is there other way that I can add the tablenames in something like an string collection or a list,or something where I can short the tablenames,or data?
I don't know how you are beginning.. but I instantiate a dataset and bring tables via an adapter and add them to the dataset. That process can be ordered.
WEll I got a problem with that cuase I'm not using an adapter, I'm using an oledbcommand to call the column from the table I want and then, I add it into the dataset as a datatable, I do that with each table I'm working with.. so in that case I can't order the tables..
Yes you can... watch this....
Private Function GetTable(Byval tablename) as Datatable
Using Adapter as Oledb.oledbDataAdapter = New OleDbDataAdapter("Select * from [" & tableName & "]" &
OrderString, con)
Dim result As New DataTable(tableName)
Try
Adapter.Fill(result)
Dataset.Tables.Add(result)
Return result Catch e as exception
end try
end function
The adapter is declared earlier.
Public
Adapter As OleDb.OleDbDataAdapter
DIsclaimers: This code was typed from memory and is conceptual and not intended for ruggedized work.
Yes but you are ordering the rows within the table not the tablesnames themself... or I'm wrong... and hat would be the orderstring
Oh,
Capture the names in a list
Do a list sort
Add them according to the order of the sorted list. If you have a fixed or known list of tables
you don't even need to do that. Just add them in your known order.
I am gettng a little curious about your design though. Why does it require a sorted order of tables in a dataset?
Do the tables have to be in an alphabetical order in the dataset - or do you just need to interpret them in an order when you get them out of the dataset.
ie. You can enter then into the dataset in any order you want and when you come to retrieve them - you would get each of the table names from the dataset, sort them and then process them in the sorted order.
Or possibly create a function to create a dataset with the tables in a sorted order - by doing the following sorting and then creating a new dataset by processing them in the appropriate order and adding the tables to a new dataset.
This way you could all this routine on any dataset to create a sorted dataset.
when I'm going to use the tables within the dataset, I need to use them in alphabetical order..
What I am asking is why?
If you require that tey be an alphabetical order in the dataset... put them in - in alphabetical order.