subset of data using dataview??

Discussion in 'ASP .Net' started by Guoqi Zheng, Jan 19, 2004.

  1. Guoqi Zheng

    Guoqi Zheng Guest

    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
    Guoqi Zheng, Jan 19, 2004
    #1
    1. Advertising

  2. Guoqi Zheng

    Marina Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Marina, Jan 19, 2004
    #2
    1. Advertising

  3. Guoqi Zheng

    Miha Markic Guest

    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
    Miha Markic, Jan 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Taylor

    Re: data from DataView

    Chris Taylor, Aug 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    390
    Chris Taylor
    Aug 28, 2003
  2. Andy
    Replies:
    0
    Views:
    413
  3. =?Utf-8?B?TWljaGHFgiBKYW51c3pjenlr?=

    DataView data accessor aware of sorting used

    =?Utf-8?B?TWljaGHFgiBKYW51c3pjenlr?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    379
    =?Utf-8?B?TWljaGHFgiBKYW51c3pjenlr?=
    Nov 22, 2004
  4. PJ6
    Replies:
    1
    Views:
    565
  5. CodeMonkey
    Replies:
    1
    Views:
    725
    joyal jhaveri
    Feb 4, 2011
Loading...

Share This Page