473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Sharing datasources among forms - VS2005

I have come across the situation several times where a number of forms
in an app use the same datasource, for example to populate a combo
drop-down. I'm sure we've all had this. Using the IDE results in
every form getting its own Dataset, BindingSource and TableAdapter,
plus code in the Open event to fill the table in the dataset. This
strikes me as incredibly inefficient - there is simply no need for
every form to go to the database to read this data in again. What I
want is a way to set up and populate a dataset once, then just refer
to it in all the forms that might need it. Is there a way to do this
that fits in with the IDE? If there is it isn't obvious to me.

Feb 24 '07 #1
4 1202
Steve,

It is strange, because the version 2003 has this behaviour. The version 2005
creates it on its own datasource where the tableadapter can be build in. It
is a class on its own including data and connection to the database.

Can you tell us how you build up your tableadapter?

Cor

"Steve Marshall" <st****@westnet.net.auschreef in bericht
news:11*********************@p10g2000cwp.googlegro ups.com...
>I have come across the situation several times where a number of forms
in an app use the same datasource, for example to populate a combo
drop-down. I'm sure we've all had this. Using the IDE results in
every form getting its own Dataset, BindingSource and TableAdapter,
plus code in the Open event to fill the table in the dataset. This
strikes me as incredibly inefficient - there is simply no need for
every form to go to the database to read this data in again. What I
want is a way to set up and populate a dataset once, then just refer
to it in all the forms that might need it. Is there a way to do this
that fits in with the IDE? If there is it isn't obvious to me.

Feb 24 '07 #2
If you were really concerned about the performance, you could create a
public class with shared properties that point to datatables that you're
using to bind to comboboxes all over your app, and access that everywhere.

Robin S.
-------------------------
"Steve Marshall" <st****@westnet.net.auwrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
>I have come across the situation several times where a number of forms
in an app use the same datasource, for example to populate a combo
drop-down. I'm sure we've all had this. Using the IDE results in
every form getting its own Dataset, BindingSource and TableAdapter,
plus code in the Open event to fill the table in the dataset. This
strikes me as incredibly inefficient - there is simply no need for
every form to go to the database to read this data in again. What I
want is a way to set up and populate a dataset once, then just refer
to it in all the forms that might need it. Is there a way to do this
that fits in with the IDE? If there is it isn't obvious to me.

Feb 26 '07 #3
Yes, an approach like that has occurred to me, and I will pursue it.
It just doesn't seem to fit as naturally as I would like with the way
the IDE does things. Thanks for the reply.
On Feb 26, 9:38 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
If you were really concerned about the performance, you could create a
public class with shared properties that point to datatables that you're
using to bind to comboboxes all over your app, and access that everywhere.

Robin S.
-------------------------"Steve Marshall" <ste...@westnet.net.auwrote in message

news:11*********************@p10g2000cwp.googlegro ups.com...
I have come across the situation several times where a number of forms
in an app use the same datasource, for example to populate a combo
drop-down. I'm sure we've all had this. Using the IDE results in
every form getting its own Dataset, BindingSource and TableAdapter,
plus code in the Open event to fill the table in the dataset. This
strikes me as incredibly inefficient - there is simply no need for
every form to go to the database to read this data in again. What I
want is a way to set up and populate a dataset once, then just refer
to it in all the forms that might need it. Is there a way to do this
that fits in with the IDE? If there is it isn't obvious to me.- Hide quoted text -

- Show quoted text -

Feb 26 '07 #4
Hi,

"Steve Marshall" <st****@westnet.net.auwrote in message
news:11*********************@z35g2000cwz.googlegro ups.com...
Yes, an approach like that has occurred to me, and I will pursue it.
It just doesn't seem to fit as naturally as I would like with the way
the IDE does things. Thanks for the reply.
<text snipped>

Here is some addition info:

After compiling the class (example) below, you can create an object Data
Source from it (Data Source's window, add new Data Source). Once you have
the Data Source you can use it with the WinForm designer and the DataTable
will only be loaded once when it's first used.

Imports WindowsApplication1.SomeDBDataSetTableAdapters

Public Class GlobalCompanyDataSource
Implements System.ComponentModel.IListSource

Public Shared _Table As SomeDBDataSet.CompanyDataTable

Public Shared ReadOnly Property Table() As
SomeDBDataSet.CompanyDataTable
Get
If (_Table Is Nothing) Then
_Table = New SomeDBDataSet.CompanyDataTable
Dim cta As New CompanyTableAdapter
cta.Fill(_Table)
cta.Dispose()
End If
Return _Table
End Get
End Property

Public ReadOnly Property ContainsListCollection() As Boolean Implements
System.ComponentModel.IListSource.ContainsListColl ection
Get
Return False
End Get
End Property

Public Function GetList() As System.Collections.IList Implements
System.ComponentModel.IListSource.GetList
Return Table.DefaultView
End Function
End Class

If your form needs to contain global and a non global DataTable's which are
part of the same DataSet, then you could just use the DataSet on the Form
and then replace the fill line in Form_Load for the global DataTable, this
way you can still enforce referential integrity (fk constraints).

Private Sub Form_Load(...)
' fill lookup (global)
SomeDBDataSet.Company.Merge(CompanyGlobalSource.Ta ble)

' fill master (non-global)
EmployeeTableAdapter.Fill(SomeDBDataSet.Employee)
End Sub
HTH,
Greetings
Feb 26 '07 #5

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

Similar topics

3
by: Robert W. | last post by:
I'm embarking on a project that will have both a desktop application and a Pocket PC application. It seems logical to have as much code as possible sitting in a shared project, which would be...
4
by: qube3 | last post by:
We have applications written by JSP/Servlet and ASP.NET. All our future development would be based on ASP.NET. We wants to develop a single user interface so that users would not be aware that...
2
by: brucedodds2 | last post by:
I have a client with an Access 97 format switchboard based application. This app is shared across several offices which are being upgraded in sequence to Access XP. Recently XP users started...
0
by: Tina | last post by:
I'm reading articles on the new TableAdapters where it says that a key new advantage is that a single TableAdapter, which can have multiple queries, can be used on multiple forms. Now that was in...
9
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: Carlo \(MCP only\) | last post by:
Hi to all I'm askyng you a suggestion about the best way to share the same source code between VS2003 and VS2005. The project I'm developing is a controls and components library, and the...
1
by: Leon_Amirreza | last post by:
Hi, I am wondering if there is a way to share a Dataset object on the main form of my C# App between other forms that I can bind other forms controls to this dataset (designer is not aware of a...
19
by: cpnet | last post by:
I'm using VS2005, C#, ASP.NET 2.0. I'm trying to create a report using SQL Reporting Services (to be used in local mode so I don't have to deal with SQL Server). When I create a new report in my...
0
by: grmiked | last post by:
Hallo everybody, I am working with VS2005 and have a major problem with VC++ and Crystal Reports that has been driving me crazy for the last 1 week! More specifically, my problem situation can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.