"There is already an open DataReader associated with this Connection which must be closed first." with MySqlCommandBuilder
Posted by: chris.cowart
Date: December 16, 2006 01:09AM

I believe I've found a bug, but someone correct me if I'm wrong. I'm still new to this, but here goes...

I get this error "There is already an open DataReader associated with this Connection which must be closed first." when I'm using MySqlCommandBuilder on a MySqlDataAdapter and call its Update function.

The code I have executes the generated queries fine, but always throws a MySqlException like I mentioned.

Here is the code that I'm having the problem with (in C#):

public partial class TableEditor : UserControl
{
MySqlConnection conn;
MySqlDataAdapter da;

DataSet ds;
DataTable dt;

MySqlCommandBuilder builder;

string tableName;

string connectionString;

public TableEditor()
{
InitializeComponent();

ds = new DataSet();
dt = new DataTable();
}

private void TableEditor_Load(object sender, EventArgs e)
{

}

public void connect(string host, string user, string pass)
{
connectionString = "Host=" + host + "; Username=" + user + "; Password=" + pass + ";";

// Init MySql
conn = new MySqlConnection(connectionString);
conn.Open();
}

public void setDatabase(string dbname)
{
conn.ChangeDatabase(dbname);
}

public void setTable(string table)
{
tableName = table;

//dt.Clear();
dt.TableName = tableName;

da = new MySqlDataAdapter("SELECT * FROM " + tableName, conn);
builder = new MySqlCommandBuilder(da);

da.TableMappings.Add("Table", tableName);

//ds.Clear();
ds.Tables.Add(dt);

da.Fill(ds);

// Event Handlers
dt.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);

// Apply it to the grid view
dataGridView1.DataSource = ds.Tables[0];
}

private void dt_RowChanged(object sender, DataRowChangeEventArgs e)
{
builder.GetUpdateCommand();
da.Update(ds, tableName);
}
}

Options: ReplyQuote


Subject
Written By
Posted
"There is already an open DataReader associated with this Connection which must be closed first." with MySqlCommandBuilder
December 16, 2006 01:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.