This is my first time here, so if I break any etiquette just let me know.
Situation:
A form that displays a "ticket" with ~10 databound comboboxes. The CB's are always display the same lists. When the form loads, it currently copies a dataset from a master that contains all the tables used in the databinding. When several tickets are open, the application is taking up a lot of memory, most of which is duplicate data.
Question:
Is it possible to perform databinding using one set of data for multiple forms, to eliminate (or reduce) duplication.
4 replies to this topic
#1
Posted 06 May 2011 - 10:05 AM
|
|
|
#2
Posted 06 May 2011 - 10:22 AM
its definitely possible.
Programmer to programmer, I shudder when I think about data binding.
But, so long as the data source was accessible to both elements, there's no reason why you couldn't.
There are some very good reasons why you shouldn't however.
Did you know that ADO.NET is built from the ground up to handle distributed copies of data ?
And so long as you follow the rules, you can handle all reconciling issues as they arise.
But anyways, if the local copy of the data, like a dataset or a datatable were somewhere visible from both forms, and declared static
if could be initialized and filled before either form were created, and then multiple forms should be able to have elements bind to it.
eg.
Programmer to programmer, I shudder when I think about data binding.
But, so long as the data source was accessible to both elements, there's no reason why you couldn't.
There are some very good reasons why you shouldn't however.
Did you know that ADO.NET is built from the ground up to handle distributed copies of data ?
And so long as you follow the rules, you can handle all reconciling issues as they arise.
But anyways, if the local copy of the data, like a dataset or a datatable were somewhere visible from both forms, and declared static
if could be initialized and filled before either form were created, and then multiple forms should be able to have elements bind to it.
eg.
class DataCache {
public static DataTable table1 { get; set; }
}
class Program {
static Main() {
adapter.fill(table1);
using (MainForm frmMain = new MainForm(table1)) { //a possible way of associating the cached data with the form
Application.Run(frmMain);
//from this point, anywhere within your project, you could reference that data by 'DataCache.table1'
}
}
}
#3
Posted 06 May 2011 - 11:15 AM
Thank you for the quick response, but I am curious now: what are the reasons for and against?
And why does databinding make you shudder?
And why does databinding make you shudder?
#4
Posted 06 May 2011 - 11:33 AM
Shuddering: Style I guess. I've been programming for a while now. And the first experience I've ever had with data binding was with legacy vb. I didn't like it at all. So much so in fact, it's left a horrible taste in my mouth, and I prefer wiring up everything myself.
I know I'm not alone on the matter, most programmers I know share my opinion. Though I suspect that some younger programmers generally like data binding. I'm expecting a followup debate :cool:
In terms of reasons for and against binding multiple controls to a single source, well how it would pan out in actuality would depend greatly on exactly what it is your building, and how it's laid out.
But in my thinking, it's a kind of singleton way of thinking. It's easier to implement, but, well, consider this pseudo code.
Intentionally left simple, but to illustrate a point.
This is in all likelihood safe, since we're only incrementing values, and we know for certain that only 10 workers will be called, and that each of those workers will increment the value 10 times.
But we also know, that we have no control over when which thread hits it next. So if we write code this way, sooner or later, something unexpected happens.
In the case of binding multiple controls to one source, I'm not sure. What if the user starts modifying the record in one form, and then flips over to another and does something different to that record, before the first commits.
What if having a single instance of all your cached data turns into a similar situation, except a change somewhere else breaks a constraint in another form that currently has something open.
It's just in my mind a lot more to think about.
I know I'm not alone on the matter, most programmers I know share my opinion. Though I suspect that some younger programmers generally like data binding. I'm expecting a followup debate :cool:
In terms of reasons for and against binding multiple controls to a single source, well how it would pan out in actuality would depend greatly on exactly what it is your building, and how it's laid out.
But in my thinking, it's a kind of singleton way of thinking. It's easier to implement, but, well, consider this pseudo code.
static int i = 0;
void worker() {
for (int i; i < 10; i++)
i++;
return;
}
static void Main() {
for(int i = 0; i < 10; i++)
(new Thread(new ThreadStart(worker))).Start();
}
Intentionally left simple, but to illustrate a point.
This is in all likelihood safe, since we're only incrementing values, and we know for certain that only 10 workers will be called, and that each of those workers will increment the value 10 times.
But we also know, that we have no control over when which thread hits it next. So if we write code this way, sooner or later, something unexpected happens.
In the case of binding multiple controls to one source, I'm not sure. What if the user starts modifying the record in one form, and then flips over to another and does something different to that record, before the first commits.
What if having a single instance of all your cached data turns into a similar situation, except a change somewhere else breaks a constraint in another form that currently has something open.
It's just in my mind a lot more to think about.
#5
Posted 06 May 2011 - 12:33 PM
Well, I am in my first year of programming, and Databinding was the first method I encountered for using tables in ComboBoxes like this. I can imagine how it would be done without Databinding, though it seems like a lot more work. Unless Databinding has a lot of overhead, and seeing as how its pretty simply in C#.net, it just feels like the easier way.
However, so many copies of this one DataSet just seemed wasteful to me, in a way that I expected a better method to exist. Like the feeling that I was being taught the slow way to perform a task.
However, so many copies of this one DataSet just seemed wasteful to me, in a way that I expected a better method to exist. Like the feeling that I was being taught the slow way to perform a task.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









