473,698 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding to a DataSet with more than one DataTable

I have a function that creates a DataSet, populates its many DataTables and
then returns the DataSet.

I want to bind separate controls to each of the DataSet's DataTables, e.g. a
separate GridView for each DataTable.

As far as I can tell, the ObjectDataSourc e only binds to the DefaultView of
the DataSet's first DataTable. I'd like to know how to bind to the other
DataTables or, if this is not possible, what alternative technique is
recomended?

Note that the overhead required to populate the DataTables is quite high
(and so I wouldn't want to call the function more than once). There are also
strong dependencies between the DataTables such that I wouldn't be able to
deliver them independently in their own separate DataSets.

Feb 5 '07 #1
9 10915
Set GridView.DataMe mber property to the table name.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Dick" <Di**@nospam.no spamwrote in message
news:DB******** *************** ***********@mic rosoft.com...
>I have a function that creates a DataSet, populates its many DataTables and
then returns the DataSet.

I want to bind separate controls to each of the DataSet's DataTables, e.g.
a
separate GridView for each DataTable.

As far as I can tell, the ObjectDataSourc e only binds to the DefaultView
of
the DataSet's first DataTable. I'd like to know how to bind to the other
DataTables or, if this is not possible, what alternative technique is
recomended?

Note that the overhead required to populate the DataTables is quite high
(and so I wouldn't want to call the function more than once). There are
also
strong dependencies between the DataTables such that I wouldn't be able to
deliver them independently in their own separate DataSets.

Feb 5 '07 #2
This was my first guess too, but the it fails with the exception shown below.

System.Argument Exception: The data source 'ObjectDataSour ceAllScoresOnRo und'
only supports a single view named 'DefaultView'. You may also leave the view
name (also called a data member) empty for the default view to be chosen.

"Eliyahu Goldin" wrote:
Set GridView.DataMe mber property to the table name.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Dick" <Di**@nospam.no spamwrote in message
news:DB******** *************** ***********@mic rosoft.com...
I have a function that creates a DataSet, populates its many DataTables and
then returns the DataSet.

I want to bind separate controls to each of the DataSet's DataTables, e.g.
a
separate GridView for each DataTable.

As far as I can tell, the ObjectDataSourc e only binds to the DefaultView
of
the DataSet's first DataTable. I'd like to know how to bind to the other
DataTables or, if this is not possible, what alternative technique is
recomended?

Note that the overhead required to populate the DataTables is quite high
(and so I wouldn't want to call the function more than once). There are
also
strong dependencies between the DataTables such that I wouldn't be able to
deliver them independently in their own separate DataSets.


Feb 5 '07 #3
Hello Dick,

I assume you are expecting functionality which is not availible when using
ObjectDataSourc e.
As Eliyahu wrote one possibility is to use DataMember but in this case you
cannot use DataSourceID property and ObjectDataSourc e. You have to set
DataSource to your DataSet and bind explicitly instead.

If you want to use ObjectDataSourc e you will probably have to create many
different select methods - it means many ObjectDataSourc es - to create 1:1
relations among GridViews and ObjectDataSourc es. You can use Cache to store
your DataSet.

Other possibility is to use one select method with parameter to control
binding to different tables in you dataset. You will have to set this
parameter in ObjectDataSourc e's Selecting event handler to use select method
on correct table in DataSet. This should be difficult.

Regards,
Ladislav Mrnka

"Dick" wrote:
I have a function that creates a DataSet, populates its many DataTables and
then returns the DataSet.

I want to bind separate controls to each of the DataSet's DataTables, e.g. a
separate GridView for each DataTable.

As far as I can tell, the ObjectDataSourc e only binds to the DefaultView of
the DataSet's first DataTable. I'd like to know how to bind to the other
DataTables or, if this is not possible, what alternative technique is
recomended?

Note that the overhead required to populate the DataTables is quite high
(and so I wouldn't want to call the function more than once). There are also
strong dependencies between the DataTables such that I wouldn't be able to
deliver them independently in their own separate DataSets.
Feb 5 '07 #4
If you already have the dataset, bind to it with DataSource property instead
of using ObjectDataSourc e.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Dick" <Di**@nospam.no spamwrote in message
news:4D******** *************** ***********@mic rosoft.com...
This was my first guess too, but the it fails with the exception shown
below.

System.Argument Exception: The data source
'ObjectDataSour ceAllScoresOnRo und'
only supports a single view named 'DefaultView'. You may also leave the
view
name (also called a data member) empty for the default view to be chosen.

"Eliyahu Goldin" wrote:
>Set GridView.DataMe mber property to the table name.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Dick" <Di**@nospam.no spamwrote in message
news:DB******* *************** ************@mi crosoft.com...
>I have a function that creates a DataSet, populates its many DataTables
and
then returns the DataSet.

I want to bind separate controls to each of the DataSet's DataTables,
e.g.
a
separate GridView for each DataTable.

As far as I can tell, the ObjectDataSourc e only binds to the
DefaultView
of
the DataSet's first DataTable. I'd like to know how to bind to the
other
DataTables or, if this is not possible, what alternative technique is
recomended?

Note that the overhead required to populate the DataTables is quite
high
(and so I wouldn't want to call the function more than once). There are
also
strong dependencies between the DataTables such that I wouldn't be able
to
deliver them independently in their own separate DataSets.



Feb 5 '07 #5
Hello Dick,

As Eliyahu has suggested, one way is to directly assign the DataSet object
to DataBound control(such a gridview)'s Datasource property and set the
proper "DataMember ". This is just like the programmatic databinding in
ASP.NET 1.X.

If you want to utilize the ObjectDataSourc e declarative databinding, you
can consider creating a wrapper class which expose a Select method that
will return the certain DataTable(from internal DataSet object) according
to a given input parameter(selec t parameter in DataSource control). e.g.

=============== ===============
public class WrapperClass
{
private MyDataSet _dataset;

public WrapperClass()
{
_dataset = new MyDataSet();
//fill in datatables here
}

public DataTable Select(string tablename)
{
return _dataset.Tables[tablename];
}
}

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

In the ObjectDataSourc e, you can supply this parameter through the
DataSource control's "Select" parameter collection(from any available
parameter sources or directly embeded in it)

===============
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="S elect"
TypeName="Wrapp erClass">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Labe l1" Name="tablename "
PropertyName="T ext" Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>
=============== ===========

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Feb 6 '07 #6
Hi Steven

Thanks for your suggestion but it overlooks the point I made in my original
question, namely that the overhead required to populate the DataTables is
quite high (and so I wouldn't want to call the function more than once).

I worked on this some more last night and think I've found an elegant and
efficient solution. I've described it below for your comment and in case it
might help others with a similar problem.

I made my business rule object stateful as below (I've made the example
losely typed for simplicity):

Public Class BR

Private m_DataSet As DataSet

Public Function GetTable1 As DataTable
Me.PopulateData Set
Return Me.m_DataSet.Ta ble1
End Function

Public Function GetTable2 As DataTable
Me.PopulateData Set
Return Me.m_DataSet.Ta ble2
End Function

Private Sub PopulateDataSet
If Me.m_DataSet Is Nothing Then
Me.m_DataSet = New DataSet
'Populate...
End If
End Sub

End Class

Then – on my web form – I overrode the process by which the ObjectDataSourc e
objects are created as below

Private m_BR As New BR

Protected Sub ObjectCreating( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Obje ctDataSourceEve ntArgs) Handles
ObjectDataSourc e1.ObjectCreati ng, ObjectDataSourc e2.ObjectCreati ng
e.ObjectInstanc e = Me.m_BR
End Sub

This ensures that the BR object is created just the once – and therefore the
associated overhead is minimised - yet I'm still able to complete all my
other binding without any more code.

Feb 6 '07 #7
Hello Dick,

Yes, you're right. Actually the class I showed in my previous reply just
demonstrate a very basic code logic about using wrapper class. Of course,
it would be necessary to cache the dataset(and its contained datatables).

One thing you can still consider here is the place where you cache the
dataset/datatables instance. From your code, you use a private variable of
the page class to hold the class BR for caching, correct? If so, this
class will still be instanced and destroyed on each page request.
Therefore, if you want to cache the DataSet/Datatables instances across
multiple page requests, you can consider use the ASP.NET Cache storage to
hold it.

http://msdn2.microsoft.com/en-us/library/ms178597.aspx

http://msdn2.microsoft.com/en-us/library/aa478965.aspx

In addition, for your below code
===========
Protected Sub ObjectCreating( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Obje ctDataSourceEve ntArgs) Handles
ObjectDataSourc e1.ObjectCreati ng, ObjectDataSourc e2.ObjectCreati ng
e.ObjectInstanc e = Me.m_BR
End Sub

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

I would also suggest you move it to your custom wrapper class(always check
the dataset/datatable instances from Cache, if not exists, load them from
backend database). How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 7 '07 #8
Cool, I'll look at that next, thanks for your help.

"Steven Cheng[MSFT]" wrote:
Hello Dick,

Yes, you're right. Actually the class I showed in my previous reply just
demonstrate a very basic code logic about using wrapper class. Of course,
it would be necessary to cache the dataset(and its contained datatables).

One thing you can still consider here is the place where you cache the
dataset/datatables instance. From your code, you use a private variable of
the page class to hold the class BR for caching, correct? If so, this
class will still be instanced and destroyed on each page request.
Therefore, if you want to cache the DataSet/Datatables instances across
multiple page requests, you can consider use the ASP.NET Cache storage to
hold it.

http://msdn2.microsoft.com/en-us/library/ms178597.aspx

http://msdn2.microsoft.com/en-us/library/aa478965.aspx

In addition, for your below code
===========
Protected Sub ObjectCreating( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Obje ctDataSourceEve ntArgs) Handles
ObjectDataSourc e1.ObjectCreati ng, ObjectDataSourc e2.ObjectCreati ng
e.ObjectInstanc e = Me.m_BR
End Sub

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

I would also suggest you move it to your custom wrapper class(always check
the dataset/datatable instances from Cache, if not exists, load them from
backend database). How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 7 '07 #9
You're welcome :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 7 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12311
by: bardo | last post by:
Does anyone knwo how I can bind a textbox to a single dataset/dataTable row? The following will give me only a Column: textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataTable, "TableNaam")) But in my program I need a textbox (that I can edit) directly bound to a fixed cel in a Dataset/ dataTable.
3
1654
by: Just D | last post by:
Hi, If anybody needs to show some data retrieved from the database table, what method is more preferrable? 1. DataSet ds = ...; DataGrid.Data.Source.ds; DataGrid.Bind(); 2. Write a custom object, fill it with the DataSet data and ÅÒÕÔ try to bind
2
3621
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the DetailsView and then handle my updating manually. -Andrew
2
4419
by: Alex S Moore | last post by:
I built a dataset with two datatables and added the relation. The example in the help text for datatable class seemed sufficient. Binding a datalist using the dataset for datasource and the parent datatable name as the datamember does not work for me. Columns from the child (or second) datatable in the dataset are not found. Using vb.net for code-behind. The binding statement for a control looks like this: Text='<%#...
0
326
by: mark | last post by:
What I have is three forms. Form one with buttons 1, 2 and 3; and forms 2 and 3 with datagrids. Button 1 populates arrays a(i,j) and b(i,j) with values. Button 2 creates a datatable containing the a(i,j) array then adds that table to a dataset which is in turn bound to a datagrid in an instance of form 2 called matrixa. Button 3 creates a datatable containing the b(i,j) array then adds that table to a dataset which is in turn bound to...
8
3924
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some addition fields. I'm able to get the datagrid to be properly populate with only the child records relating to the specified parent by setting the ..DefaultView.RowFilter property. Currently, to properly add a new child record, I need to manually...
2
2104
by: pwh777 | last post by:
I need help in understanding the DataAdapter Fill method and how it relates to the binding to controls on a form. I have a table called tbl_CID_XRef on SQL Server. I have written as a test the simple code below: ---------------------------------------------------------------- Private cob As SqlCommandBuilder Private con As SqlConnection Private cur As CurrencyManager
0
1098
by: A.J | last post by:
There is a : 1.DataGrid: Columns-->firstName,LastName,EMail,PhoneNumber 2.GroupBox: controls-->4 TextBoxes(firstName,LastName,EMail,PhoneNumber) 3.Both DataGrid and GroupBox are binded to the same datasource(Dataset) and Share the same BINDINGCONTEXT ie on clicking a record in the grid;we can see the same record in the groupbox. $$$$$$$$$$$$$$$$$$$$$$Edited $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
10
5839
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi, Problem: How can I databind (or put) a SqlServer query's row return of 115,000 items into a ComboBox quickly? Not much longer than a matter of seconds, that is... Scenario: I am rebuilding my company's Access 97 VBA database app. It pulls 115,000 items (of account names) from SqlServer and the data is bound to a single Access 97 ComboBox control. My C# version needs to work exactly like this one. Our executive employees want...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.