473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Q: Sorting Relations

Hi

I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column
contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff
Nov 20 '05 #1
6 1084
Hi Geoff,

Why not select them with as the sort order the dates?

Cor
I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column
contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff

Nov 20 '05 #2
Hi Cor

Could you give some example code?

Goeff

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl...
Hi Geoff,

Why not select them with as the sort order the dates?

Cor
I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column
contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff


Nov 20 '05 #3
Hi Geoff

Dim myselectstring as string = "Select * in MyDetailTable order by mydates"

Than your table is sorted not depending the relation, it looks so simple,
where do I understand you wrong?

Maybe you can as well use the dataview I see now, for which I gave you a
sample in that other message, when you are using two datagrids (one master
and one detail)

Cor
Hi Geoff,

Why not select them with as the sort order the dates?

Cor
I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff



Nov 20 '05 #4
Hi Cor

Yes, I can see what you mean. However, I am dealing with events after the
DataAdaptor. I was trying to do it via a DataTable or DataRow. My
understanding what you could only do a Select etc. during the
DataAdaptor/Connection stage and not once you have a DataTable or DataRow?

Geoff

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
Hi Geoff

Dim myselectstring as string = "Select * in MyDetailTable order by mydates"
Than your table is sorted not depending the relation, it looks so simple,
where do I understand you wrong?

Maybe you can as well use the dataview I see now, for which I gave you a
sample in that other message, when you are using two datagrids (one master
and one detail)

Cor
Hi Geoff,

Why not select them with as the sort order the dates?

Cor

> I have two tables to which I have created a one-to-many relationship. >
> How do I sort the result of the relationship? For example, if one column > contains dates, how do I display in the dates in order in a DataGrid? >
> Thanks in advance
>
> Geoff
>
>



Nov 20 '05 #5
Geoff,
Have you tried using a DataViewManager?

Something like (modified sample from MSDN sample):

' Create a Connection, DataAdapters, and a DataSet.
Dim connection As SqlConnection = New SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")

Dim customerAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT
CustomerID, CompanyName FROM Customers", connection)
Dim orderAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT
OrderID, CustomerID FROM Orders", connection)
Dim orderDetailsAdapter As SqlDataAdapter = New
SqlDataAdapter("SELECT OrderID, ProductID, Quantity FROM [Order Details]",
connection)

Dim customerDataSet As DataSet = New DataSet

' Open the Connection.
connection.Open()

' Fill the DataSet with schema information and data.
customerAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
orderAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
orderDetailsAdapter.MissingSchemaAction =
MissingSchemaAction.AddWithKey

customerAdapter.Fill(customerDataSet, "Customers")
orderAdapter.Fill(customerDataSet, "Orders")
orderDetailsAdapter.Fill(customerDataSet, "OrderDetails")

' Close the Connection.
connection.Close()

' Create relationships.
customerDataSet.Relations.Add("CustomerOrders", _
customerDataSet.Tables("Customers").Columns("Custo merID"), _
customerDataSet.Tables("Orders").Columns("Customer ID"))

customerDataSet.Relations.Add("OrderDetails", _
customerDataSet.Tables("Orders").Columns("OrderID" ), _
customerDataSet.Tables("OrderDetails").Columns("Or derID"))

' Create default DataView settings.
Dim viewManager As DataViewManager = New
DataViewManager(customerDataSet)

For Each viewSetting As DataViewSetting In
viewManager.DataViewSettings
viewSetting.ApplyDefaultSort = True
Next

' Set sort order for each table.
viewManager.DataViewSettings("Customers").Sort = "CompanyName"
viewManager.DataViewSettings("Orders").Sort = "OrderID"
viewManager.DataViewSettings("OrderDetails").Sort = "ProductID"

' Bind to three DataGrids.
Me.DataGrid1.SetDataBinding(viewManager, "Customers")
Me.DataGrid2.SetDataBinding(viewManager, "Customers.CustomerOrders")
Me.DataGrid3.SetDataBinding(viewManager,
"Customers.CustomerOrders.OrderDetails")

Note we are binding to a ViewManager instead of the DataSet directly.

Hope this helps
Jay
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column
contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff

Nov 20 '05 #6
Interesting!

Thanks Jay

Geoff

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
Geoff,
Have you tried using a DataViewManager?

Something like (modified sample from MSDN sample):

' Create a Connection, DataAdapters, and a DataSet.
Dim connection As SqlConnection = New SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")

Dim customerAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT
CustomerID, CompanyName FROM Customers", connection)
Dim orderAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT
OrderID, CustomerID FROM Orders", connection)
Dim orderDetailsAdapter As SqlDataAdapter = New
SqlDataAdapter("SELECT OrderID, ProductID, Quantity FROM [Order Details]",
connection)

Dim customerDataSet As DataSet = New DataSet

' Open the Connection.
connection.Open()

' Fill the DataSet with schema information and data.
customerAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey orderAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
orderDetailsAdapter.MissingSchemaAction =
MissingSchemaAction.AddWithKey

customerAdapter.Fill(customerDataSet, "Customers")
orderAdapter.Fill(customerDataSet, "Orders")
orderDetailsAdapter.Fill(customerDataSet, "OrderDetails")

' Close the Connection.
connection.Close()

' Create relationships.
customerDataSet.Relations.Add("CustomerOrders", _
customerDataSet.Tables("Customers").Columns("Custo merID"), _
customerDataSet.Tables("Orders").Columns("Customer ID"))

customerDataSet.Relations.Add("OrderDetails", _
customerDataSet.Tables("Orders").Columns("OrderID" ), _
customerDataSet.Tables("OrderDetails").Columns("Or derID"))

' Create default DataView settings.
Dim viewManager As DataViewManager = New
DataViewManager(customerDataSet)

For Each viewSetting As DataViewSetting In
viewManager.DataViewSettings
viewSetting.ApplyDefaultSort = True
Next

' Set sort order for each table.
viewManager.DataViewSettings("Customers").Sort = "CompanyName"
viewManager.DataViewSettings("Orders").Sort = "OrderID"
viewManager.DataViewSettings("OrderDetails").Sort = "ProductID"

' Bind to three DataGrids.
Me.DataGrid1.SetDataBinding(viewManager, "Customers")
Me.DataGrid2.SetDataBinding(viewManager, "Customers.CustomerOrders") Me.DataGrid3.SetDataBinding(viewManager,
"Customers.CustomerOrders.OrderDetails")

Note we are binding to a ViewManager instead of the DataSet directly.

Hope this helps
Jay
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

I have two tables to which I have created a one-to-many relationship.

How do I sort the result of the relationship? For example, if one column
contains dates, how do I display in the dates in order in a DataGrid?

Thanks in advance

Geoff


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alvaro G Vicario | last post by:
I have this test code: <html><pre><? echo "Versión: ".phpversion()."\n\n"; $define_list = array( 'PRODUCT_LIST_MODEL' => 0, 'PRODUCT_LIST_NAME' => 0,
11
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
4
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
1
by: Jef De Rycke | last post by:
Hi access group, I have written code to create relations between tables according to a corresponding relations information table. At first I thought my code was not working properly because...
8
by: Matthew Curiale | last post by:
I am creating an app that lists clients of a company for management of different attributes for that company. The first page is a listing of the companies currently in the database. I have my...
1
by: Randy Fraser | last post by:
How do I create a relationship on muliple columns in an untyped dataset. Why does this not work. da.Fill(ds) ds.Tables(0).TableName = "DesignSummary" ds.Tables(1).TableName = "FormulaSummary"...
2
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the #...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.