Datagridview refresh issue

R

RSH

Hi,

I have a situation where I have a DDL that lists all of the tables in a
particular database, and a Datagridview which appears in the same from below
the DDL.. When the user selects a new database table from the list I
refresh the datagridview with the newly selected tables data.

This works fine but after a few tables have been selected it takes a very
long time to load some of the tables. Some tables that contain only one row
of information take longer to load than a table that has 2000 records. It
isn't consistent as far as I can tell either. I have even had a couple
users complain of a "Object Required" error which I have been able to
reproduce in the compile but not stepping through code.

This seems like I am not clearing something out properly, or something is
hanging. When it hangs in code it is always at the same line: da.Fill(dt);

Here is the snippet of code:
dt.Clear();

Application.DoEvents();

String connectionString = "Data Source=" + strCurSQLServer+ "; Integrated
Security=SSPI; Initial Catalog=master";

SqlConnection cnSQL = new SqlConnection(connectionString);

dataGridView1.DataSource = bindingSource1;

da.SelectCommand = new SqlCommand(selectCommand, cnSQL);

SqlCommandBuilder builder = new SqlCommandBuilder(da);

dataGridView1.DataSource = bindingSource1;

lblStatus.Text = "Loading Data...";

lblRecordCount.Text = "";

Application.DoEvents();

da.Fill(dt);

lblRecordCount.Text = "Returned " + strSQLTable + " - " +
dt.Rows.Count.ToString() + " rows";

bindingSource1.DataSource = dt;

dataGridView1.Columns[0].ReadOnly = true;

Application.DoEvents();


Is there anything I can check or clean up to make this more responsive?

Thanks!
Ron
 

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