how to fill a dataset using something OTHER than a SQL query?

Discussion in 'ASP .Net' started by darrel, May 5, 2005.

  1. darrel

    darrel Guest

    I have this:

    Dim aFiles as FileInfo() = dirInfo.GetFiles("*.*")

    Does this create an array?

    I'd like to walk through each item and then render out some text. My initial
    thought was to attach the data to a dataset, walk through it, and then grab
    the info as needed.

    I haven't done much with arrays, though, and I can't seem to find an example
    of filling a dataset with anything other than an XML file or DB query.

    -Darrel
     
    darrel, May 5, 2005
    #1
    1. Advertising

  2. darrel

    JV Guest

    Darrel,

    You can bind controls directly to the array that is returned by GetFiles(),
    it is not required to convert it to a DataSet necessarily.

    However, you should be aware that you can construct your own DataSet object,
    add a DataTable and add rows to it if you should ever need to.


    "darrel" <> wrote in message
    news:...
    >I have this:
    >
    > Dim aFiles as FileInfo() = dirInfo.GetFiles("*.*")
    >
    > Does this create an array?
    >
    > I'd like to walk through each item and then render out some text. My
    > initial
    > thought was to attach the data to a dataset, walk through it, and then
    > grab
    > the info as needed.
    >
    > I haven't done much with arrays, though, and I can't seem to find an
    > example
    > of filling a dataset with anything other than an XML file or DB query.
    >
    > -Darrel
    >
    >
     
    JV, May 5, 2005
    #2
    1. Advertising

  3. darrel

    darrel Guest

    > However, you should be aware that you can construct your own DataSet
    object,
    > add a DataTable and add rows to it if you should ever need to.


    I guess that's my question...how does one do that? I can bind the data right
    to a repeater control, for instance, but I'd like to actually walk through
    the datarows myself. It seems the easiest way to do that would be to pass
    the array data into a dataset. I'm not sure how to go about that, though.

    -Darrel
     
    darrel, May 5, 2005
    #3
  4. darrel

    Lucas Tam Guest

    "darrel" <> wrote in
    news::

    >> However, you should be aware that you can construct your own DataSet

    > object,
    >> add a DataTable and add rows to it if you should ever need to.

    >
    > I guess that's my question...how does one do that? I can bind the data
    > right to a repeater control, for instance, but I'd like to actually
    > walk through the datarows myself. It seems the easiest way to do that
    > would be to pass the array data into a dataset. I'm not sure how to go
    > about that, though.



    Here's some pseudo code:

    Dim DS as New DataSet
    Dim DT as New DataTable
    Dim DC as New DataColumn("Mycolumn", System.Type.GetType
    ("System.String")
    DT.Columns.add(DC)
    DS.Tables.add(DS)

    Dim DR as DataRow = DS.Tables(0).NewRow()
    DR("MyColumn") = "Hello World"

    DS.Tables(0).Rows.add(DR)


    The above code will create your own DataSet.

    To bind data manually, use the ItemDataBound event.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-
    us/cpref/html/frlrfsystemwebuiwebcontrolsdatalistclassitemdataboundtopic
    ..asp

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, May 5, 2005
    #4
  5. darrel

    darrel Guest

    > Here's some pseudo code:
    >
    > Dim DS as New DataSet
    > Dim DT as New DataTable
    > Dim DC as New DataColumn("Mycolumn", System.Type.GetType
    > ("System.String")
    > DT.Columns.add(DC)
    > DS.Tables.add(DS)
    >
    > Dim DR as DataRow = DS.Tables(0).NewRow()
    > DR("MyColumn") = "Hello World"
    >
    > DS.Tables(0).Rows.add(DR)


    I think I'm missing a key concept here.

    So, the above will make a dataset, but where's it getting the data from? How
    to I take the data from the FileInfo() object and put it into the ds?

    Or, maybe I'm going about this wrong...is it possible to just read through
    the FileInfo() object item by item directly?

    -Darrel
     
    darrel, May 5, 2005
    #5
  6. darrel

    Lucas Tam Guest

    "darrel" <> wrote in
    news:uKYI$:

    >> Dim DR as DataRow = DS.Tables(0).NewRow()
    >> DR("MyColumn") = "Hello World"
    >>
    >> DS.Tables(0).Rows.add(DR)

    >
    > I think I'm missing a key concept here.
    >
    > So, the above will make a dataset, but where's it getting the data
    > from? How to I take the data from the FileInfo() object and put it
    > into the ds?
    >
    > Or, maybe I'm going about this wrong...is it possible to just read
    > through the FileInfo() object item by item directly?


    You need to reach item one by one.


    For example:

    'Get new datarow
    Dim DR as DataRow = DS.Tables(0).NewRow()

    For each directory as string in FileInfo()
    DR("Directory") = directory
    'Add row back into table
    DS.Tables(0).Rows.add(DR)
    Next


    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, May 6, 2005
    #6
    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. Andy Fish
    Replies:
    2
    Views:
    3,078
    Andy Fish
    Aug 11, 2004
  2. Anonymous
    Replies:
    0
    Views:
    1,475
    Anonymous
    Oct 13, 2005
  3. Jaime Wyant
    Replies:
    9
    Views:
    335
    Michael Hoffman
    Mar 31, 2005
  4. Pekka Järvinen
    Replies:
    2
    Views:
    668
    Richard Tobin
    Apr 29, 2008
  5. K. Frank
    Replies:
    17
    Views:
    374
    Jorgen Grahn
    Jun 4, 2013
Loading...

Share This Page