SqlDataSource / manually searching the selected rows.

  • Thread starter Thread starter Brian Mitchell
  • Start date Start date
B

Brian Mitchell

How do I iterate through the records returned by a SqlDataSource through
code? I have it set to return the results to a dataset but I don't know how
to access that dataset. This is for an ASPX page and I don't have the
dataset control in my tools.

Thanks!
 
Brian,

In VB Net code a dataset looks like this.

dataset.Tables(collectionOf).Rows(collectionof).Items(Collectionof)
C#
dataset.Tables[x].Rows[x].Items[x]

This means in VB see it for yourself if C# was needed

dataset.Tables(0).Rows(0).Items(0) is the first item in the first row in the
first table from the dataset
dim dt = dataset.Tables(0)
dt.Rows(dt.Rows.Count-1) ' it the last row

Etc. etc.

I hope this helps,

Cor
 
Thank you for the reply. I can't see where the SqlDataSource exposes the
dataset object, I have the DataSource dragged to the web page and if I bind
a grid to it, the correct data is displayed. However, I have a need to go
through the records via code and I can't see any way to get the records out
of the SqlDataSource. I am using the new tools in VB2005.

Thanks again!!
 
I did figure it out (I think). I'm not sure if I'm doing the correct way for
2005 but the select method returns an IEnumerable which I can set to the
dataset. So, in my case I have
ds=SqlDataSource.Select(Web.UI.DataSourceSelectArguments.Empty).
 
Brian,

I am not yet there in 2005 with ASPNET and a strongly typed dataset to give
you maybe a correct answer.

However, if it is a non strongly dataset, than we have forever to save the
dataset in a session. That is why a dataset is automaticly serialized.

Something as in the load event in a kind of pseudo code
If not IsPostedBack then
create dataset
session(mydataset) = createddataset
Else
dataset = session(mydataset)
End if

I hope that this gives an idea.

Cor
 
Back
Top