Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randomizing datarow location when merging datatables 1

Status
Not open for further replies.

DotNetBlocks

Programmer
Apr 29, 2004
161
US
Hello,
How can I merge 3 data.datatables so that all the datarows are mixed up together?

Code:
Example:

table 1
tr1
tr2
tr3
tr4
tr5

table2
te1
te2
te3
te4
te5

table 3
tb1
tb2
tb3
tb4

Result:
----------
merged table
te5
tb1
tr3
tr5
te2
tb4
tb3
tr1
te3
te1
tb2
tr2
tr4
tb3
tb5


Babloome
 
The order in which records are stored in the underlying table is never guaranteed in a relational database, so you could:

Add an additional row in the merged table in which you store a random number and then base usage of the merged table on a sort by the random number field.


Hope this helps.

[vampire][bat]
 
Sorry:

[tt]Add an additional row in the merged table [/tt]

should have been:

[tt]Add an additional column in the merged table [/tt]


Hope this helps.

[vampire][bat]
 
How do you set a sort order once I have the random number in the new column?

Babloome
 
If the new column is called RandNumCol and the main column is called MainCol then your SQL statement needs to be something like:

[tt]SELECT MainCol FROM MyMergergedTable ORDER BY RandNumCol[/tt]


Hope this helps.

[vampire][bat]
 
got the sort.


myDVM.DataViewSettings["Customers"].Sort =
"CompanyName DESC"
 
... and if I could spell [tt]merged[/tt] properly that would have been so much better.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top