|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
AccessDataSource - how to get access to the retrieved data?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? -- It''s Software Jim, but not as we know it! 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. Hi Steven,
Thanks for your quick response > ... you're wondering how to access the underlying DataTable in memory Yes indeed!> (generated by the AccessDataSource control) ,correct? > ... it doesn't naturally expose a property or method that allow us to hook Ah, that's a bit of bad luck. Maybe Dot.Net V3 ;-)> the underlying DataTable it generated ... > ... you can consider manually call the Possible yes. Do I want that? Actually not for the things I already have in > AccessDataSource control's Select method to get the > underlying dataobject and bind it to GridView e.g: 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 = or in VB> AccessDataSource1.Select(DataSourceSelectArguments.Empty) as DataView; 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 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.
Adding Web Control
How can I find the datakey of currently selected row? what' wrong with this? sqldatasource and connection exception handling Help! Menu control not rendering properly on production Gridview: Edit row validation Turning URL Navigation off on a Treeview Trigger an Insert on a FormView control Get GridView index from DataKey Accessing selected value from a masterpage/webpart control from the content page? |
|||||||||||||||||||||||