filtering with dataviewmanager

M

mmj

I have a DataViewManager created from a DataSet that had 2 tables and a
relationship.

Table(0)
--CustomerID
--CustomerName
--CustomerAddress

Table(1)
--OrderID
--CustomerID
--OrderDate
--OrderTotalAmount

All customer and their associated order records are in these tables, I am
being passed a string that could look like any of the following,

"CustomerID = '100'"
"CustomerID = '50' AND OrderDate = '1/1/2002'"
"OrderTotalAmount > '1000.00'"
etc....

and I am trying to find the best way to filter the data, then loop through
it so I can return it to the calling app, in a custom format.
Is the DataViewManager the best way to deal with this?

---All suggestions and sample code appreciated.
mmj
 
H

Hussein Abuthuraya[MSFT]

You need to create a DataView object and set its Filter property to the
string that you have. The data that will show in the DataView object will
be the criteria matched rows.

da1 = New SqlDataAdapter("select * from Customers", myConnection)
da2 = New SqlDataAdapter("select * from orders", myConnection)
da1.Fill(myDataSet, "customers")
da2.Fill(myDataSet, "Orders")

myDataSet.Relations.Add("CustOrders",
myDataSet.Tables("Customers").Columns("CustomerId"),
myDataSet.Tables("Orders").Columns("CustomerId"))

Dim dv1 As DataView
dv1 = myDataSet.Tables("Customers").DefaultView
dv1.Sort = "CompanyName"
dv1.RowFilter = "Country = 'Germany'"
DataGrid2.DataSource = dv1

dv2 = myDataSet.Tables("Orders").DefaultView
dv2.RowFilter = "CustomerID = ..."
dv2.Sort = "OrderDate"
DataGrid3.DataSource = dv2

You also could use the DataViewManager i na similar fashion. See the .NET
SDK for sample code if needed.

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2004 Microsoft Corporation. All rights
reserved

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
M

mmj

Thanks for the feedback, however, it is the approach with the
DataViewManager that I would like to see a code sample on and cant seem to
find any on MSDN or Google of in the SDK... if anyone has code samples using
the DataViewManager that would be much appreciated.

--thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top