AccessDataSource - how to get access to the retrieved data?

M

Martin

I am using the new AccessDataSource control and it works as expected (query
result bound to a GridView).

Very nice about this control is that it keeps the data in memory. (a
Dataset). But how can I get that data, and use it elsewhere in my code?

I have read that a method exists (GetView) which would return a
AccessDataSourceView. This is however a protected method, so I can't use it
on the instance that I dropped on the form ...

Also I do not want to iterate the rows from the bound GridView.

So, how do you return the dataset?
 
S

Steven Cheng[MSFT]

Hi Martin,

From your description, I understand you're using the ASP.NET 2.0
AccessDataSource control to query some data from a certain mdb data file
and display it on a GridView through DataBinding. However, you're
wondering how to access the underlying DataTable in memory(generated by the
AccessDataSource control) ,correct?

As for the AccessDataSource control(same as SqlDatasource control) , it
doesn't naturally expose a property or method that allow us to hook the
underlying DataTable it generated and asociate to databinding control(when
we use DataSourceID) to bind the data.

For your scenario, I'm wondering whether you just want to query the data
for display only or is it possible that we use programmatic databinding
here instead of DataSourceID? If this is possible, you can consider
manually call the AccessDataSource control's Select method to get the
underlying dataobject and bind it to GridView e.g:


===================
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataView dv =
AccessDataSource1.Select(DataSourceSelectArguments.Empty) as DataView;

GridView1.DataSource = dv;
GridView1.DataBind();

}

}
=====================

Thus, you can get the reference to the DataView object.


Another solution is to use ObjectDataSource instead of AccessDataSource,
and you can create a TableAdapter/DataSet pair for querying data from
Access mdb file. The VS 2005 IDE can help create typed TableAdapter and
DataSet conveniently through user interface, and you can either use the
TableAdapter programmtically or configure it in ObjectDataSource and use
it, here are some related msdn reference:

#TableAdapters in Visual Studio 2005
http://msdn.microsoft.com/library/en-us/dnvs05/html/tableadapters.asp?frame=
true

#ObjectDataSource
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/objectdatas
ource.aspx

After you bind ObjectDataSource to GridView, you can use the
ObjectDataSource.Selected event to hook the underlying returned data
object. e.g

==============
protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
Response.Write("<br/>" + e.ReturnValue.GetType());

}
===============

Please feel free to let me know if you have anything unclear or if there is
any else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Martin

Hi Steven,

Thanks for your quick response
... you're wondering how to access the underlying DataTable in memory
(generated by the AccessDataSource control) ,correct?

Yes indeed!
... it doesn't naturally expose a property or method that allow us to hook
the underlying DataTable it generated ...

Ah, that's a bit of bad luck. Maybe Dot.Net V3 ;-)
... you can consider manually call the
AccessDataSource control's Select method to get the
underlying dataobject and bind it to GridView e.g:

Possible yes. Do I want that? Actually not for the things I already have in
place!
But there's ofcourse no problem in using both methods together. I just leave
the things I did at design time as it is (DatasourceID for binding the
controls)

Additionally I create the view in code using the same control. The answer
that did it for me is the following line:
DataView dv =
AccessDataSource1.Select(DataSourceSelectArguments.Empty) as DataView;

or in VB

Dim dv As DataView =
CType(AccessDataSource1.Select(DataSourceSelectArguments.Empty), DataView)

and now I can iterate the view for the individual records!

Great. Exactly what I was looking for.

ThanX
 
S

Steven Cheng[MSFT]

Thanks for your quick reply Martin,

Glad that the information helps you.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top