how to remove databinding

J

jp2msft

We have a database with one table of 15000 employees and 21 fields. (Yes, it
needs to be restructured, but that isn't happening today).

I have a DataGridView that is databound to the table. Whenever the
application starts, it takes about 5-10 seconds to populate this DataGrid
(depending on how congested our internal network is).

I also have ComboBox controls for each of the individual fields in the
database. Before, I was filling these in programatically from data in the
TableAdapter for the DataGridView.

While reading through a "How-To" book, I saw where I could have my
ComboBoxes also bound to the data. Hoping for increased effeciency, I data
bound each of my 21 ComboBoxes with a column from my table.

Now, whenever I start my application, instead of taking 5-10 seconds to
populate the DataGridView and display the form, it now takes (5-10 seconds) *
(1 DataGridView + 21 ComboBoxes) to show the form.

Ouch! I thought my application had crashed for an unknown reason!

How do I "unbind" these controls now? There isn't anything in this "How-To"
book on undoing the evils it started.

Regards,
Joe

"How-To" book: Microsoft Visual Basic 2005 "Step by Step"
 
C

Cowboy \(Gregory A. Beamer\)

Unbinding is the opposite of binding. You have to remove each binding point.

Before going too far, you have another issue you need to solve here and that
is the database access time. Unless this is a file based database on an
ancient computer with huge network lag, there has to be something you can do
to speed up access time. 15000 records should be nothing, especially to a
properly indexed database.

I also have an issue with the databinding, as it should not cause that much
of a problem, when done correctly. There are a couple of possibilities:

1. The book shows an inefficient method of data binding.
2. Your data access method is causing too many callbacks to get data. Rather
than binding from data already gathered, it is binding some elements and
then making a callback per row (ouch!).

Without knowing more about your setup, I cannot make firm recommendations,
but I would fully troubleshoot the problem prior to hacking at the
application.

On another note, this is the reason why some form of source control is a
great idea. You can easily roll back to the last working version without
having to hack things out. If your company will not allow you to implement
real source control, save your app before you experiment so you can use copy
and paste source control. It is not the wisest method, but it is better than
nothing.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
C

Cor Ligthert[MVP]

jp2msft,

I am curious how you want to do use those comboboxes without databinding.
The databinding will not the problem, however I assume that there are
datatables (or any other from the database collected table class) as
datasource (bindingsource) for those boxes. Probably is the problem the
retrieval of those tables.

Cor
 
J

jp2msft

You seem to know your stuff with database programming, so I'll venture to ask
you another question:

Whenever I place a "data aware" control on my form (DataGridView, ComboBox,
etc.) and specify what table it is to get data from using the Wizard, VS
creates controls with names based on the table names.

So, the "Manager/Supervisor" table MGRSPV would produce mGRSPVTableAdapter
and fill it with using the m_dsEmpInfo DataSet:

Code:
this.mGRSPVTableAdapter.Fill(this.m_dsEmpInfo.MGRSPV);

Once this DataSet has been filled:

1) Should I treat the DataSet as a complete table that I work from?
Originally, I only had one DataSet; so to get other data queries, I would
send different SQL commands to the TableAdapter and fill the DataSet again.
I'm beginning to think that this is wrong, but I haven't seen anything that
says, "Don't do this!"

2) How would I run a query on a DataSet (like this.m_dsEmpInfo.MGRSPV,
above)? Does the result from that query need to go into another DataSet?

I want my DataGridView to be dynamic and show different views of data for
different options our operators will be selecting, but I don't know the best
way to re-fill a DataGridView.

Thanks for your help, too! This isn't the sort of thing that is covered in
any "How-To" books or website tutorials.

Regards,
Joe
 
J

jp2msft

This is the hangup:

1. DataSet ds = new DataSet("EmpInfo");
2. da = new SqlDataAdapter(sqlCmd, conn);
3. da.Fill(m_dsCpApp, "EmployeeInfo");
4. dgEmpInfo.DataSource = m_dsCpApp.Tables["EmployeeInfo"].DefaultView;

Lines 2 & 3 both take a while.
 
G

Guru

jp2msft said:
This is the hangup:

1. DataSet ds = new DataSet("EmpInfo");
2. da = new SqlDataAdapter(sqlCmd, conn);
3. da.Fill(m_dsCpApp, "EmployeeInfo");
4. dgEmpInfo.DataSource = m_dsCpApp.Tables["EmployeeInfo"].DefaultView;

Lines 2 & 3 both take a while.

If it is the case that both 2 & 3 "take a while" then it is the case that
the operation at 2 exposes the root cause. The solution is simple.

Get a better network.
 
J

jp2msft

An employee might be moved to a different department, change shifts, etc.

If the ComboBoxes are data bound, I am unable to make changes.

Is there a better way?
 
C

Cor Ligthert[MVP]

The problems with the comboboxes is always that the index changes as soon as
you change something in that and then that event fires.

What I do in those cases is remove the event handler in the beginnen of the
event in the index change event and add it again at the end. (This works
both in C# and VB the same, however with complete different code)

Cor
 

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

Top