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

accessing typed dataset relationships?

I am trying to understand typed datasets more.... and i am stuck on a little problem

I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes.
the news has news_id int, title string and type int
the news type table has type_id int and type_name string
There is also a relationship created which is joining on the news.type and then newstype.type_id

In the code below i am putting in 2 rows for types... and 1 row for a news article.

My question is .... how can i get the STRING value of the newstype that relates to my news item? eg i want an easy way to get to the value "first type"

Any help would me much appreciated.

News myNews = new News();
News.NewsTypesRow tRow;

// Add some types
tRow = myNews.NewsTypes.NewNewsTypesRow();
tRow.type_id = 1;
tRow.type_name = "first type";

tRow.type_id = 2;
tRow.type_name = "second type";

// Add some datat to the news
News.NewsTableRow nRow = myNews.NewsTable.NewNewsTableRow();
nRow.title = "news title";
nRow.type = 1;
MessageBox.Show(nRow.title.ToString());
Nov 18 '05 #1
3 1399
Here is the XSD

<?xml version="1.0" encoding="utf-8" ?>

<xs:schema id="News" targetNamespace="http://tempuri.org/News.xsd" elementFormDefault="qualified"

attributeFormDefault="qualified" xmlns="http://tempuri.org/News.xsd" xmlns:mstns="http://tempuri.org/News.xsd"

xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:element name="News" msdata:IsDataSet="true">

<xs:complexType>

<xs:choice maxOccurs="unbounded">

<xs:element name="NewsTable">

<xs:complexType>

<xs:sequence>

<xs:element name="news_id" type="xs:int" minOccurs="0" />

<xs:element name="title" type="xs:string" minOccurs="0" />

<xs:element name="type" type="xs:int" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="NewsTypes">

<xs:complexType>

<xs:sequence>

<xs:element name="type_id" type="xs:int" minOccurs="0" />

<xs:element name="type_name" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

<xs:key name="NewsKey1" msdata:PrimaryKey="true">

<xs:selector xpath=".//mstns:NewsTable" />

<xs:field xpath="mstns:news_id" />

</xs:key>

<xs:key name="NewsKey2">

<xs:selector xpath=".//mstns:NewsTypes" />

<xs:field xpath="mstns:type_id" />

</xs:key>

<xs:keyref name="NewsTypesNewsTable" refer="NewsKey2" msdata:ConstraintOnly="true">

<xs:selector xpath=".//mstns:NewsTable" />

<xs:field xpath="mstns:type" />

</xs:keyref>

</xs:element>

</xs:schema>

"Darren Clark" <dc******@hotmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl...
I am trying to understand typed datasets more.... and i am stuck on a little problem

I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes.
the news has news_id int, title string and type int
the news type table has type_id int and type_name string
There is also a relationship created which is joining on the news.type and then newstype.type_id

In the code below i am putting in 2 rows for types... and 1 row for a news article.

My question is .... how can i get the STRING value of the newstype that relates to my news item? eg i want an easy way to get to the value "first type"

Any help would me much appreciated.

News myNews = new News();
News.NewsTypesRow tRow;

// Add some types
tRow = myNews.NewsTypes.NewNewsTypesRow();
tRow.type_id = 1;
tRow.type_name = "first type";

tRow.type_id = 2;
tRow.type_name = "second type";

// Add some datat to the news
News.NewsTableRow nRow = myNews.NewsTable.NewNewsTableRow();
nRow.title = "news title";
nRow.type = 1;
MessageBox.Show(nRow.title.ToString());
Nov 18 '05 #2
"Darren Clark" <dc******@hotmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl...
I am trying to understand typed datasets more.... and i am stuck on a little problem

I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes.
the news has news_id int, title string and type int
the news type table has type_id int and type_name string
There is also a relationship created which is joining on the news.type and then newstype.type_id

In the code below i am putting in 2 rows for types... and 1 row for a news article.

My question is .... how can i get the STRING value of the newstype that relates to my news item? eg i want an easy way to get to the value "first type"

Any help would me much appreciated.

News myNews = new News();
News.NewsTypesRow tRow;

// Add some types
tRow = myNews.NewsTypes.NewNewsTypesRow();
tRow.type_id = 1;
tRow.type_name = "first type";
New<type>Row() just creates a new row object of the type. It doesn't add the new row to the DataSet. Try

myNews.NewsTypes.Add(tRow).

Also, you need another new row here:

tRow = myNews.NewsTypes.NewNewsTypesRow();

tRow.type_id = 2;
tRow.type_name = "second type";
myNews.NewsTypes.Add(tRow)
// Add some datat to the news
News.NewsTableRow nRow = myNews.NewsTable.NewNewsTableRow();
nRow.title = "news title";
nRow.type = 1;
myNews.NewsTable.Add(nRow);

--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #3
OK i have changed my code now to add the rows... but i still cant access the values in the other table..
It doesnt matter if i use getparentrow or getchildrows ... both fail..

however i know that the relationship works because if i try and add the value 5 to a news row it fails. and returns a FK error.

News myNews = new News();
News.NewsTypeRow tRow;

// Add some types

tRow = myNews.NewsType.NewNewsTypeRow();

tRow.type_id = 1;

tRow.name = "first type";

myNews.NewsType.Rows.Add(tRow);

tRow = myNews.NewsType.NewNewsTypeRow();

tRow.type_id = 2;

tRow.name = "second type";

myNews.NewsType.Rows.Add(tRow);
// Add some datat to the news

News.NewsTableRow nRow = myNews.NewsTable.NewNewsTableRow();
nRow.type_id = 1;

nRow.body = "some coppy here";

myNews.NewsTable.Rows.Add(nRow);
MessageBox.Show(nRow.body.ToString());
DataRow pRow = nRow.GetParentRow("NewsTypeNewsTable");

if (pRow == null)

{

MessageBox.Show("p is null");

}

else

{

MessageBox.Show(pRow[0].ToString());

}

DataRow[] pRows = nRow.GetChildRows("NewsTypeNewsTable");
MessageBox.Show(pRows.Length.ToString()); // RETURNS 0

"John Saunders" <jo**************@notcoldmail.com> wrote in message news:uT**************@tk2msftngp13.phx.gbl...
"Darren Clark" <dc******@hotmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl...
I am trying to understand typed datasets more.... and i am stuck on a little problem

I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes.
the news has news_id int, title string and type int
the news type table has type_id int and type_name string
There is also a relationship created which is joining on the news.type and then newstype.type_id

In the code below i am putting in 2 rows for types... and 1 row for a news article.

My question is .... how can i get the STRING value of the newstype that relates to my news item? eg i want an easy way to get to the value "first type"

Any help would me much appreciated.

News myNews = new News();
News.NewsTypesRow tRow;

// Add some types
tRow = myNews.NewsTypes.NewNewsTypesRow();
tRow.type_id = 1;
tRow.type_name = "first type";
New<type>Row() just creates a new row object of the type. It doesn't add the new row to the DataSet. Try

myNews.NewsTypes.Add(tRow).

Also, you need another new row here:

tRow = myNews.NewsTypes.NewNewsTypesRow();

tRow.type_id = 2;
tRow.type_name = "second type";
myNews.NewsTypes.Add(tRow)
// Add some datat to the news
News.NewsTableRow nRow = myNews.NewsTable.NewNewsTableRow();
nRow.title = "news title";
nRow.type = 1;
myNews.NewsTable.Add(nRow);

--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #4

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

Similar topics

0
by: Steve Holm stephen.w.holm | last post by:
Hi everyone, Is it possible to have a strongly typed dataset and then replace a table? This is driving me nuts! If both the current datatable and the new datatable are the same type, why...
2
by: George Grodentzik | last post by:
I created a typed dataset from which I am trying to access the data. When I use the following code to access a row string name =dataset.person.firstName I receive an error...
3
by: MC D | last post by:
I have a situation in which I have a strongly typed dataset based on the schema of a xml document. This works great, and OMG I love strongly typed datasets... ;o) However, The situation I have...
0
by: Karl | last post by:
Hi, In SQL server, I created a Person table with a spouseID field, which refers to PersonID as the foreign key. It is like this: PersonID (primary key), PersonName, SpouseID (foreign key refer...
1
by: Mythran | last post by:
Which would be the better solution? 1.) 20 Tables In 1 DataSet, no relationships. 2.) 20 DataSet's with 1 Table each. The tables have no relationship with each other (although they...
4
by: Dave Taylor | last post by:
I've been using the dataset designer in Visual Studio to create typed datasets for my application by dragging over tables from the Server Explorer and dropping them into the designer. The problem...
8
by: Dot Net Newbie | last post by:
New to DOTNET so please be gentle: I have an in-memory dataset that I want move to a SQL Server database. The XML schema with which the dataset was built matches exactly the table schema in SQL...
3
by: Tolga Erdogus | last post by:
Hi, for a project that I am wrapping up I am writing documentation. I'd like to be able to put in xmldoc style comments in to the source of my strongly typed dataset, its tables, relationshipts...
2
by: Tony Girgenti | last post by:
Hello I developed and tested a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1. It uses a web form. I used the XML Designer to create an XML .XSD...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.