473,386 Members | 1,721 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,386 software developers and data experts.

Selecting from a Dataset? ASP.NET

Hello,

I have a dataset with 2 tables. I want to display only selected data
from one of these tables.

The table names are Albums and Tracks. That Dataset is called
AlbumsTracks

If I only wanted to select those tracks that had a common AlbumID as
those in Albums - how would I get this out of a dataset?

Pseudo code:
Select * from Tracks where AlbumID=Albums.AlbumID
from Dataset Albums tracks.

Syntax? Or is there a smarter method?

Thanks,

Tmuld.
Jul 19 '05 #1
3 10490
JJ
Table objects have a Select method which enables filtering
and sorting of data. For your application try:

DataRow[] rows = Tracks.Select("AlbumID=" +
someAlbumID.ToString());

For readonly filtering, use a DataView Filter instead.
-----Original Message-----
Hello,

I have a dataset with 2 tables. I want to display only selected datafrom one of these tables.

The table names are Albums and Tracks. That Dataset is calledAlbumsTracks

If I only wanted to select those tracks that had a common AlbumID asthose in Albums - how would I get this out of a dataset?

Pseudo code:
Select * from Tracks where AlbumID=Albums.AlbumID
from Dataset Albums tracks.

Syntax? Or is there a smarter method?

Thanks,

Tmuld.
.

Jul 19 '05 #2
Pat
You could use a DataRelation object.
Pseudo Code:
- create dataset
- read table albums
- read table tracks
- create DataRelation object for tracks <--> albums

alternatively, (and quicker)
is to create a stored procedure and run it from the data
adapter instead of a query:

CREATE PROCEDURE [dbo].[GetAlbums]
AS
BEGIN
Select Tracks.* from Tracks T inner join Albums A ON
T.AlbumID = A.AlbumID
END

The second method should work in any standard T-SQL
enabled db such as MySQL, INTERBASE, MS-SQL or Access.
You would need to check specific formatting, especially
for Access and INTERBASE.

Hope this helps.
-----Original Message-----
Hello,

I have a dataset with 2 tables. I want to display only selected datafrom one of these tables.

The table names are Albums and Tracks. That Dataset is calledAlbumsTracks

If I only wanted to select those tracks that had a common AlbumID asthose in Albums - how would I get this out of a dataset?

Pseudo code:
Select * from Tracks where AlbumID=Albums.AlbumID
from Dataset Albums tracks.

Syntax? Or is there a smarter method?

Thanks,

Tmuld.
.

Jul 19 '05 #3
You would need to create A Data Relation between those Data Tables in the
dataset, and then you can navigate each album row's children using this
syntax:

For each DataRow track in MyAlbumRow.GetChildren(RelationName)
{
// loop through all the children.
}

If you want to show all the child rows in a datagrid, you can bind the grid
directly to the relation by setting its DataSource to the dataset, and its
datamember to "MasterTableName.RelationName".

Then just bind the Albums table to another grid and watch the magic...

Good Luck.
--
Regards,

Roy Osherove
http://www.iserializable.com
---------------------------------------------

"Tavish Muldoon" <tm******@spliced.com> wrote in message
news:e2**************************@posting.google.c om...
Hello,

I have a dataset with 2 tables. I want to display only selected data
from one of these tables.

The table names are Albums and Tracks. That Dataset is called
AlbumsTracks

If I only wanted to select those tracks that had a common AlbumID as
those in Albums - how would I get this out of a dataset?

Pseudo code:
Select * from Tracks where AlbumID=Albums.AlbumID
from Dataset Albums tracks.

Syntax? Or is there a smarter method?

Thanks,

Tmuld.

Jul 19 '05 #4

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

Similar topics

2
by: Sam74 | last post by:
Hi, I'm writing a program with Microsoft Visual C# .net version 2002 the program has 4 Forms and all the database components (DataSet, OleDbDataAdapter, OleDbConnection) are in form4 as I've got...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
4
by: rodchar | last post by:
Hey all, Is there a way to get similar functionality as the SELECT DISTINCT records in a SQL Statement when selecting records from a dataset? thanks, rodchar
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
3
by: Anthony | last post by:
Hi There When trying to add a dataset to a web form I get the following error msg. "There were problems generating . To resolve this problem build the project, fix the errors and generate...
6
by: Mike Wilson | last post by:
Dear Group, I have a heirarchical set of database tables, say - "order" and "order_type" and want to display a series of orders in a grid control, and in place of the order_type foreign key...
9
by: =?Utf-8?B?RGljaw==?= | last post by:
I have a function that creates a DataSet, populates its many DataTables and then returns the DataSet. I want to bind separate controls to each of the DataSet's DataTables, e.g. a separate...
1
by: vbDavidC | last post by:
I am adding a new record to a table via a dataset/adapter. I have got the following to work for me but I am wondering if there is a better way to do this. I am having to have something in my...
3
by: mark.norgate | last post by:
Hi Another problem... My drop down is always defaulting to selecting the first item in the drop down, even though I've got code specifically to change it to a different item: Dim adapter...
5
by: hollyquinn | last post by:
Hi I am working with a web application where I am selecting values from a SQL Server 2005 database and then loading the values into different controls on my page. Most of the values load with no...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...

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.