P
Paul W
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"
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"