Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > subset of data using dataview??

Reply
Thread Tools

subset of data using dataview??

 
 
Guoqi Zheng
Guest
Posts: n/a
 
      01-19-2004
Dear sir,

New to ASP.NET, help will be appreciated.

I need to create a XML file for product feed. In our business, one product
always belongs to more than 1 categories. I need to have a XML file like.
<product id = "105">
<Name>whatever</Name>
<Categories>
<Category name = "Category1"/>
<Category name = "Category2"/>
.....
</Categories>
</product>

I can use a dataset which get the data from product table. However, my
question is that how can I get a sub set data of category. The category
rows varies depends on the product id. I am thinking to use dataview filter.
The following is my code.
.......
dvCategory = New DataView(dtCategory)
strView = "ProductId='"&r("ProductId")&"'"
dvCategory.RowFilter= strView
For Each rCat in dvCategory.Table.Rows
Writer.WriteStartElement("category")
Writer.WriteAttributeString("name",
rCat("CatName")&r("ProductId"))
Writer.WriteEndElement()
Next
....

It will write out all the categories instead of only those categories this
product belongs to. Any idea what did I do wrong or how can I achieve this??

Thanks in advanced.

Guoqi Zheng
Tel: 0031-23-5343545
http://www.meetholland.com


 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      01-19-2004
This is because you are still grabbing all the rows from the underlying
table. The underlying table never changes, but the dataview can filter which
rows you see.

You should be looking at the Item property of the DataView to get each row
as filtered from the dataview instead.

"Guoqi Zheng" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dear sir,
>
> New to ASP.NET, help will be appreciated.
>
> I need to create a XML file for product feed. In our business, one product
> always belongs to more than 1 categories. I need to have a XML file like.
> <product id = "105">
> <Name>whatever</Name>
> <Categories>
> <Category name = "Category1"/>
> <Category name = "Category2"/>
> .....
> </Categories>
> </product>
>
> I can use a dataset which get the data from product table. However, my
> question is that how can I get a sub set data of category. The category
> rows varies depends on the product id. I am thinking to use dataview

filter.
> The following is my code.
> .......
> dvCategory = New DataView(dtCategory)
> strView = "ProductId='"&r("ProductId")&"'"
> dvCategory.RowFilter= strView
> For Each rCat in dvCategory.Table.Rows
> Writer.WriteStartElement("category")
> Writer.WriteAttributeString("name",
> rCat("CatName")&r("ProductId"))
> Writer.WriteEndElement()
> Next
> ....
>
> It will write out all the categories instead of only those categories this
> product belongs to. Any idea what did I do wrong or how can I achieve

this??
>
> Thanks in advanced.
>
> Guoqi Zheng
> Tel: 0031-23-5343545
> http://www.meetholland.com
>
>



 
Reply With Quote
 
 
 
 
Miha Markic
Guest
Posts: n/a
 
      01-19-2004
Hi,


> For Each rCat in dvCategory.Table.Rows
> Writer.WriteStartElement("category")
> Writer.WriteAttributeString("name",
> rCat("CatName")&r("ProductId"))
> Writer.WriteEndElement()
> Next
> ....
>
> It will write out all the categories instead of only those categories this
> product belongs to. Any idea what did I do wrong or how can I achieve

this??

You should loop through DataView' DataRowView:
foreach (DataRowView drv in dv)

Write...(drv["name"]);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I select a subset of text in a textbox using JavaScript? PJ6 ASP .Net 1 12-03-2005 05:44 PM
Forms-Based Authentication for only a subset of pages =?Utf-8?B?QW5kcmU=?= ASP .Net 2 12-30-2004 04:33 PM
Deploying a subset of an asp.Net app =?Utf-8?B?S2V2aW4gQmFua3M=?= ASP .Net 0 10-21-2004 12:55 PM
validators subset news.microsoft.com ASP .Net 1 05-27-2004 10:28 PM
Datagrid - populate with subset of an XML file Andy ASP .Net 0 05-24-2004 03:53 PM



Advertisments