R
RSH
Hi,
I have a situation where I have a datagridview on a form. I am making a
dynamic table editor where users select a database table and then it calls
this function where the data in the datagrid refreshes with the new table.
Everything works good except every susequent table that is selected is
appended to the data grid view. How do I flush out the data from the
previous bind so that only the new table is displayed?
Thanks,
Ron
private void GetData(string selectCommand)
{
try
{
String connectionString = "Data Source=myDS; Integrated Security=SSPI;
Initial Catalog=master";
SqlConnection cnSQL = new SqlConnection(connectionString);
BindingSource bindingSource1 = new BindingSource();
dataGridView1.DataSource = bindingSource1;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(selectCommand, cnSQL);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
table.Clear();
da.Fill(table);
lblRecordCount.Text = "Table: " + strSQLTable + " - " +
table.Rows.Count.ToString() + " rows";
bindingSource1.DataSource = table;
dataGridView1.Columns[0].ReadOnly = true;
}
catch (SqlException e)
{
MessageBox.Show(e.Message.ToString());
}
}
I have a situation where I have a datagridview on a form. I am making a
dynamic table editor where users select a database table and then it calls
this function where the data in the datagrid refreshes with the new table.
Everything works good except every susequent table that is selected is
appended to the data grid view. How do I flush out the data from the
previous bind so that only the new table is displayed?
Thanks,
Ron
private void GetData(string selectCommand)
{
try
{
String connectionString = "Data Source=myDS; Integrated Security=SSPI;
Initial Catalog=master";
SqlConnection cnSQL = new SqlConnection(connectionString);
BindingSource bindingSource1 = new BindingSource();
dataGridView1.DataSource = bindingSource1;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(selectCommand, cnSQL);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
table.Clear();
da.Fill(table);
lblRecordCount.Text = "Table: " + strSQLTable + " - " +
table.Rows.Count.ToString() + " rows";
bindingSource1.DataSource = table;
dataGridView1.Columns[0].ReadOnly = true;
}
catch (SqlException e)
{
MessageBox.Show(e.Message.ToString());
}
}