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

D

darrel

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
 
J

JV

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.
 
D

darrel

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
 
L

Lucas Tam

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
 
D

darrel

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
 
L

Lucas Tam

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top