473,624 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dataviews and constrained datasources?

Hi,

I have a couple of datagrids that are based on dataviews.
If I filter dataview1 I would like to automatically filter
dataview2. I posted something about this before but I
think I didn't specifically focus about that I was using
dataviews and just datagrids. Ken Tucker was nice enough
to share an example using datagrids and
relations/constraints from code (thanks ken). I was able
to duplicate this example using components and physical
datasets/tables, physical connection, etc. I kind of have
the idea now about using this like

datagrid2.SetDa tabinding(datas et1, "tbl1, tbl1tbl2")

which restricts the 2nd datagrid (based on tbl2) from a
selection from the first datagrid (based on tbl1). I
guess in the dataviews you use Rowfilter to restric rows.
So if I filter dataview1 on some field, I get x number of
rows. This gives me some unique row IDS. I then want to
filter dataview2 based on this list of ID's. This is not
the problem:

dataview2.RowFi lter = "ID In (" & strCriteria & ")"

where strCriteria contains the list of IDs which I get
from a loop from the rows in dataview1. It just seems a
little kludgy. The question is if I can restrict the
datatable of dataview2 at the source rather than using
RowFilter. Can this be done the same way as a datagrid
binding to the relation? Is the dataview limited to the
RowFilter or is there a way to constrain the dataview
datasource at the source table level?

Thanks,
Jerry
Nov 20 '05 #1
3 1898
Hi Jerry,

It is funny, I was checking something on a question from Bill and now I see
I can maybe use that message 3 times in questions in this newsgroup. I give
you a part of the text what seems for me intresting for you.

I do not know if it answers your question, however I see a lot of
connections to it. (All in a real environment needed Try's are deleted)

\\\
Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n AND A.n = 10"
Dim Conn As New OleDbConnection (connString)
Dim da As New OleDbDataAdapte r(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
'In this sample the datarelation is in my opinion not needed
'However without that A.n = 10 than it is needed
'------------------------------
Dim drlA As New DataRelation _
("AA", ds.Tables("A"). Columns("A.n"), _
ds.Tables("B"). Columns("B.n"))
ds.Relations.Ad d(drlA)
Dim dv As New DataView(ds.Tab les("A"))
DataGrid1.DataS ource = dv
DataGrid1.Expan d(-1)
////
'Without datarelation just change dv in ds

See also this to show why the Where and not the Join

http://support.microsoft.com/default...b;en-us;318646

I hope this helps?

Cor

Nov 20 '05 #2
Hi Cor,

Maybe it's a problem for me, but I am using components (I
should probably starting doing it in code). Maybe my
approach of restricting records using the
dataview.RowFil ter method isn't so bad. But one more
question if I may:

So I have these 2 tables in my dataset. If I were to
declare a dataview in code

Dim dv2 As New DataView(ds.Tab les("B"))

Could I do something like this:

Dim dv As New DataView(ds.Tab les("Select t1.* From B t1
Join A t2 On t1.ID = t2.ID"))

or something like that?

In the meantime, one other approach was to use a currency
manager object on the first dataview and do this:

Dim drView As DataRowView
drView = DirectCast(curM gr.Current, DataRowView)
dv2.RowFilter = "Id = " & drView("Id").To String()

This seems less kludgy than looping for ID's but it also
only returns 1 ID. My actual goal is to steer away from
kludgy :).

Thanks,
Jerry

-----Original Message-----
Hi Jerry,

It is funny, I was checking something on a question from Bill and now I seeI can maybe use that message 3 times in questions in this newsgroup. I giveyou a part of the text what seems for me intresting for you.
I do not know if it answers your question, however I see a lot ofconnections to it. (All in a real environment needed Try's are deleted)
\\\
Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n AND A.n = 10"
Dim Conn As New OleDbConnection (connString)
Dim da As New OleDbDataAdapte r(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
'In this sample the datarelation is in my opinion not needed'However without that A.n = 10 than it is needed
'------------------------------
Dim drlA As New DataRelation _
("AA", ds.Tables("A"). Columns("A.n"), _
ds.Tables("B"). Columns("B.n"))
ds.Relations.Ad d(drlA)
Dim dv As New DataView(ds.Tab les("A"))
DataGrid1.Data Source = dv
DataGrid1.Expa nd(-1)
////
'Without datarelation just change dv in ds

See also this to show why the Where and not the Join

http://support.microsoft.com/default.aspx?scid=kb;en- us;318646
I hope this helps?

Cor

.

Nov 20 '05 #3
Hi Jerry,

Dim dv As New DataView(ds.Tab les("Select t1.* From B t1
Join A t2 On t1.ID = t2.ID"))
No, there is a table.select which does something almost the same as the
rowfilter and people think often that it is the same as an SQL select. There
is also a table.compute.
(I find the rowfilter for the select much nicer and it is faster)
In the meantime, one other approach was to use a currency
manager object on the first dataview and do this:

Dim drView As DataRowView
drView = DirectCast(curM gr.Current, DataRowView)
dv2.RowFilter = "Id = " & drView("Id").To String()

This seems less kludgy than looping for ID's but it also
only returns 1 ID. My actual goal is to steer away from
kludgy :).


Some find it, I do not, when you put this completly in a loop it is very
clear and it can be a very small loop. Do not think that one compound
instruction is always faster. (Do not forget to set the datarow.sort before
that makes it very fast).

For a loop is not so much needed.
The spending time in your system is mostly the drawing on screen.

Cor
Nov 20 '05 #4

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

Similar topics

3
459
by: softengine | last post by:
Can and how do you alter a data view to include a look up field from another data table? The data table of the dataview only has the key, the value I need is in another data table. Can and how to you reference the value of a column in a data table/view from the row filter string of a different data view. I'm using a strongly typed dataset. Below is more info.
2
1478
by: Pablo | last post by:
Hi people, Necesito crear n dataviews en tiempo de ejecucion. I need to create "n" DataViews in runtime. I tried creating an array this way: Dim LDView As Array = Array.CreateInstance(GetType(DataView), 10)
0
1562
by: Greg | last post by:
Anyone having issues with their object datasources appearing and vanishing from the datasource browser? I create an object for binding as a datasource in my App_Code folder, compile my web project and it appears in the datasources in the report designer. Then I will make an aspx, setup a reportviewer control for my new report, go back to the rdlc and the object datasource sometimes just vanishes. I refresh, no luck.
9
2898
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... There are articles on the new TableAdapters where it says that a key new advantage is that a single TableAdapter, which can have multiple queries, can be used on multiple forms. Now that was in an article on using TableAdapters with...
4
1392
by: Bernie Hunt | last post by:
I currently have a datagrid that I'm feeding with a DataSet, which contains three tables. I would like to use a DataView to format the DataTables but I'm not sure how to go about this. Currently I have; dsVendorContacts is a DataSet with three tables and relational links dgVendors is a DataGrid With dgVendors
0
1169
by: Owen Richardson | last post by:
I have a page that displays a news article in a form view feeding off a datasource that just picks up the id from a query string. I want to add functionality for related links - so i created a stored procedure that takes three parameters. On the page i have added a second datasource which calls my stored proc, and spits out the results into a Repeater. Currently however the two datasources are independant - my second data source takes 3...
1
2039
by: Magnus | last post by:
I have a set of typed datasets that are tied to a database on a mssql2005 server. They are naturally displayed and available in the DataSources window. Now I want to rename the database, but when I do that and reconfigure any of the datasets with the Wizard, all the datatables I have previously selected are marked as unavailable (with a red x next to it), and displays all database objects in the renamed database as "new" and unchecked. ...
3
7232
by: jobs | last post by:
I've got a gridview that does not have a datasourceid assigned in the markup. I'd like to switch between two datasources in the codebehind. when I do switch, I first reset the the gridviewx.datasource = nothing and gridviewx.datasourceid = nothing before setting it to gridviewx.datasource = newdatasoruceid and then rebinding. All appears to work well until I try to excute a delete command that
19
3150
by: cpnet | last post by:
I'm using VS2005, C#, ASP.NET 2.0. I'm trying to create a report using SQL Reporting Services (to be used in local mode so I don't have to deal with SQL Server). When I create a new report in my website, nothing shows up in the Website Data Sources window. I added a few different strongly-typed Datasets to my website, and they don't show up. The only way I could get anything to show up was to create a new class that's derived from a...
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.