VB SqlDataSource.Select

M

mschmidt18

Hi, I am writing my first web app in VB.Net, after being very familiar
with C#.Net. I am trying to store the results of the
SqlDataSource.Select() method. In C#, the select method returns a
DataView, which you can manipulate very easily. But I have not had
success using the same method in VB. I did have success using
Enumerators, but i would like to work with the data in a DataTable.

here is some of my code:

in C#:

DataView dv = (DataView)
sdsDataSource.Select(DataSourceSelectArguments.Empty);
int count = dv.Table.Rows.Count();
...... whatever else


in VB, i got this to work

Dim ie As IEnumerable
ie = sdsDataSource.Select(DataSourceSelectArguments.Empty)
Dim dt As IEnumerator = ie.GetEnumerator()
while dt.MoveNext()
Dim dr As System.Data.DataRowView = dt.Current()
Response.Write(dr(0).ToString())
....whatever else
end while

Is it possible to cast an IEnumberable as a DataView or DataTable? I
really want to be able to count the number of rows, and work with the
data in a DataTable.

Thanks!
 
M

mschmidt18

I guess i really just needed to hear my problem out loud! after i
wrote it, i did it the same way as C#............

VB

Dim dv As System.Data.DataView
dv = CType(sdsGetFormNo.Select(DataSourceSelectArguments.Empty),
System.Data.DataView)
Dim myField As String = dv.Table.Rows(0)(0).ToString()


Hope this can help someone else!
 
P

Patrice

And similarly you have a for each (two words) statement instead of
enumerating by hand in case you would need that at a later time...
 

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

Top