I have 2 tables in a DataSet, tlbProducts and tblOrders. The tables are
related using prodID fields. I want to show tblOrders in a DataGrid and
replace the prodID value that is displayed in the grid with the prodDesc
value from tblProducts. My current solution is to create a new field in
tblOrders and use an Expression (dtOrders.Columns("product").Expression() =
"Parent.prodDesc") to get the value. What I don't like is when I use
ds.WriteXml to persist the dataset, the new expression field is included in
the xml file. Another note to point out is that I am using a DataView as
the source for the DataGrid so it reflect any changes made to the data.
Here is some sample code showing what I am currently doing. Is there a
better/easier way?
'build Products table
dtProd = New DataTable("tblProducts")
dtProd.Columns.Add("prodID", GetType(Integer))
'set primary key
dtProd.Columns("prodID").Unique = True
dtProd.PrimaryKey = New DataColumn() {dtProd.Columns("prodID")}
dtProd.Columns("prodID").AutoIncrement = True
dtProd.Columns("prodID").AutoIncrementSeed = 1
dtProd.Columns("prodID").AutoIncrementStep = 1

dtProd.Columns.Add("prodDesc", GetType(String))
dtProd.Columns.Add("listPrice", GetType(Decimal))
ds.Tables.Add(dtProd)

'build orders table
dt1 = New DataTable("tblOrders")
dt1.Columns.Add("orderID", GetType(Int32))
' Set PrimaryKey
dtOrders.Columns("orderID").Unique = True
dtOrders.PrimaryKey = New DataColumn() {dtOrders.Columns("orderID")}
dtOrders.Columns("orderID").AutoIncrement = True
dtOrders.Columns("orderID").AutoIncrementSeed = 1
dtOrders.Columns("orderID").AutoIncrementStep = 1

dtOrders.Columns.Add("custID", GetType(Integer))
dtOrders.Columns.Add("prodID", GetType(Integer))
dtOrders.Columns.Add("soldPrice", GetType(Decimal))
dtOrders.Columns.Add("soldDate", GetType(Date))
'add table to ds dataset
ds.Tables.Add(dtOrders)

'build relationships
ds.Relations.Add("fkProdOrder", ds.Tables("tblProducts").Columns("prodID"),
ds.Tables("tblOrders").Columns("prodID"))
ds.Relations("logVehicles").Nested = False
'add the column name to the table to show the actual product description
dtOrders.Columns.Add("product", GetType(String))
dtOrders.Columns("product").Expression() = "Parent.prodDesc"

RE: DataGrid that shows relational column value? by ilyatum

ilyatum
Fri Aug 15 18:31:53 CDT 2003

Paul,

If you do not want particular column to be saved to XML, just set
ColumnMapping property of this column to MappingType.Hidden.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Paul W" <pdweb4444@comcast.net>
>Newsgroups: microsoft.public.dotnet.framework.compactframework
>Subject: DataGrid that shows relational column value?
>Lines: 51
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <1Yb%a.23401$2x.1689@rwcrnsc52.ops.asp.att.net>
>NNTP-Posting-Host: 12.253.93.209
>X-Complaints-To: abuse@comcast.net
>X-Trace: rwcrnsc52.ops.asp.att.net 1060981629 12.253.93.209 (Fri, 15 Aug
2003 21:07:09 GMT)
>NNTP-Posting-Date: Fri, 15 Aug 2003 21:07:09 GMT
>Organization: Comcast Online
>Date: Fri, 15 Aug 2003 21:07:09 GMT
>Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!news.maxwell.syr.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3
!attbi_feed4!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail
>Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31076
>X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
>I have 2 tables in a DataSet, tlbProducts and tblOrders. The tables are
>related using prodID fields. I want to show tblOrders in a DataGrid and
>replace the prodID value that is displayed in the grid with the prodDesc
>value from tblProducts. My current solution is to create a new field in
>tblOrders and use an Expression (dtOrders.Columns("product").Expression() =
>"Parent.prodDesc") to get the value. What I don't like is when I use
>ds.WriteXml to persist the dataset, the new expression field is included in
>the xml file. Another note to point out is that I am using a DataView as
>the source for the DataGrid so it reflect any changes made to the data.
>Here is some sample code showing what I am currently doing. Is there a
>better/easier way?
>'build Products table
>dtProd = New DataTable("tblProducts")
>dtProd.Columns.Add("prodID", GetType(Integer))
>'set primary key
>dtProd.Columns("prodID").Unique = True
>dtProd.PrimaryKey = New DataColumn() {dtProd.Columns("prodID")}
>dtProd.Columns("prodID").AutoIncrement = True
>dtProd.Columns("prodID").AutoIncrementSeed = 1
>dtProd.Columns("prodID").AutoIncrementStep = 1
>
>dtProd.Columns.Add("prodDesc", GetType(String))
>dtProd.Columns.Add("listPrice", GetType(Decimal))
>ds.Tables.Add(dtProd)
>
>'build orders table
>dt1 = New DataTable("tblOrders")
>dt1.Columns.Add("orderID", GetType(Int32))
>' Set PrimaryKey
>dtOrders.Columns("orderID").Unique = True
>dtOrders.PrimaryKey = New DataColumn() {dtOrders.Columns("orderID")}
>dtOrders.Columns("orderID").AutoIncrement = True
>dtOrders.Columns("orderID").AutoIncrementSeed = 1
>dtOrders.Columns("orderID").AutoIncrementStep = 1
>
>dtOrders.Columns.Add("custID", GetType(Integer))
>dtOrders.Columns.Add("prodID", GetType(Integer))
>dtOrders.Columns.Add("soldPrice", GetType(Decimal))
>dtOrders.Columns.Add("soldDate", GetType(Date))
>'add table to ds dataset
>ds.Tables.Add(dtOrders)
>
>'build relationships
>ds.Relations.Add("fkProdOrder", ds.Tables("tblProducts").Columns("prodID"),
>ds.Tables("tblOrders").Columns("prodID"))
>ds.Relations("logVehicles").Nested = False
>'add the column name to the table to show the actual product description
>dtOrders.Columns.Add("product", GetType(String))
>dtOrders.Columns("product").Expression() = "Parent.prodDesc"
>
>
>


Re: DataGrid that shows relational column value? by Paul

Paul
Fri Aug 15 21:40:44 CDT 2003

Thanks for the simple answer!

""Ilya Tumanov [MS]"" <ilyatum@online.microsoft.com> wrote in message
news:xKXHtV4YDHA.460@cpmsftngxa06.phx.gbl...
> Paul,
>
> If you do not want particular column to be saved to XML, just set
> ColumnMapping property of this column to MappingType.Hidden.
>
> Best regards,
>
> Ilya
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> --------------------
> >From: "Paul W" <pdweb4444@comcast.net>
> >Newsgroups: microsoft.public.dotnet.framework.compactframework
> >Subject: DataGrid that shows relational column value?
> >Lines: 51
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> >Message-ID: <1Yb%a.23401$2x.1689@rwcrnsc52.ops.asp.att.net>
> >NNTP-Posting-Host: 12.253.93.209
> >X-Complaints-To: abuse@comcast.net
> >X-Trace: rwcrnsc52.ops.asp.att.net 1060981629 12.253.93.209 (Fri, 15 Aug
> 2003 21:07:09 GMT)
> >NNTP-Posting-Date: Fri, 15 Aug 2003 21:07:09 GMT
> >Organization: Comcast Online
> >Date: Fri, 15 Aug 2003 21:07:09 GMT
> >Path:
>
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
>
m!news.maxwell.syr.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3
> !attbi_feed4!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail
> >Xref: cpmsftngxa06.phx.gbl
> microsoft.public.dotnet.framework.compactframework:31076
> >X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
> >
> >I have 2 tables in a DataSet, tlbProducts and tblOrders. The tables are
> >related using prodID fields. I want to show tblOrders in a DataGrid and
> >replace the prodID value that is displayed in the grid with the prodDesc
> >value from tblProducts. My current solution is to create a new field in
> >tblOrders and use an Expression (dtOrders.Columns("product").Expression()
=
> >"Parent.prodDesc") to get the value. What I don't like is when I use
> >ds.WriteXml to persist the dataset, the new expression field is included
in
> >the xml file. Another note to point out is that I am using a DataView as
> >the source for the DataGrid so it reflect any changes made to the data.
> >Here is some sample code showing what I am currently doing. Is there a
> >better/easier way?
> >'build Products table
> >dtProd = New DataTable("tblProducts")
> >dtProd.Columns.Add("prodID", GetType(Integer))
> >'set primary key
> >dtProd.Columns("prodID").Unique = True
> >dtProd.PrimaryKey = New DataColumn() {dtProd.Columns("prodID")}
> >dtProd.Columns("prodID").AutoIncrement = True
> >dtProd.Columns("prodID").AutoIncrementSeed = 1
> >dtProd.Columns("prodID").AutoIncrementStep = 1
> >
> >dtProd.Columns.Add("prodDesc", GetType(String))
> >dtProd.Columns.Add("listPrice", GetType(Decimal))
> >ds.Tables.Add(dtProd)
> >
> >'build orders table
> >dt1 = New DataTable("tblOrders")
> >dt1.Columns.Add("orderID", GetType(Int32))
> >' Set PrimaryKey
> >dtOrders.Columns("orderID").Unique = True
> >dtOrders.PrimaryKey = New DataColumn() {dtOrders.Columns("orderID")}
> >dtOrders.Columns("orderID").AutoIncrement = True
> >dtOrders.Columns("orderID").AutoIncrementSeed = 1
> >dtOrders.Columns("orderID").AutoIncrementStep = 1
> >
> >dtOrders.Columns.Add("custID", GetType(Integer))
> >dtOrders.Columns.Add("prodID", GetType(Integer))
> >dtOrders.Columns.Add("soldPrice", GetType(Decimal))
> >dtOrders.Columns.Add("soldDate", GetType(Date))
> >'add table to ds dataset
> >ds.Tables.Add(dtOrders)
> >
> >'build relationships
> >ds.Relations.Add("fkProdOrder",
ds.Tables("tblProducts").Columns("prodID"),
> >ds.Tables("tblOrders").Columns("prodID"))
> >ds.Relations("logVehicles").Nested = False
> >'add the column name to the table to show the actual product description
> >dtOrders.Columns.Add("product", GetType(String))
> >dtOrders.Columns("product").Expression() = "Parent.prodDesc"
> >
> >
> >
>