NpgsqlCommandBuilder automatic sql commands configuration #179

Closed
czarnul opened this Issue Mar 7, 2014 · 4 comments

4 participants

@czarnul

When i use NpgsqlCommandBuilder with NpgsqlDataAdapter i always want to configure update,insert,delete commands. Earlier when i used Npgsql 2.0.1.0 version this code works fine:

DataTable t = new DataTable();            
NpgsqlConnection con = new NpgsqlConnection("some connection string");
con.Open();
NpgsqlDataAdapter adp = new NpgsqlDataAdapter("select id,description from device", con); //where id is primary key
adp.Fill(t);
NpgsqlCommandBuilder bld = new NpgsqlCommandBuilder(adp);
DataRow r = t.NewRow();
r[0] = 300001;
t.Rows.Add(r);
DataRow[] rows = new DataRow[1];
rows[0] = r;
adp.Update(rows);
con.Close();

Now with Npgsql 2.0.14.3 this code doesn`t work and all our projects must be changed because we have

InvalidOperationException

Now we must everywhere where we use Adapter and Builder before adp.Update() do this:

adp.InsertCommand = bld.GetInsertCommand();
adp.UpdateCommand = bld.GetUpdateCommand();
adp.DeleteCommand = bld.GetDeleteCommand();
@GaryK4

I am testing PostreSQL coming from MySql and I got this same error. At least, I know how to work around the problem now until it is fixed. In my case it was also bound to a Datagridview.

@franciscojunior franciscojunior added the bug label Apr 8, 2014
@franciscojunior franciscojunior added this to the 2.2 milestone Apr 8, 2014
@franciscojunior
Npgsql member

Nice, @GaryK4 !

I'll work on this issue.

@roji roji pushed a commit to roji/Npgsql that referenced this issue Jul 21, 2014
Shay Rojansky Unit test to reproduce #179 84cd371
@roji roji self-assigned this Jul 21, 2014
@roji
Npgsql member

@franciscojunior, I'll take a look at this in the coming days...

@roji roji added a commit to roji/Npgsql that referenced this issue Jul 25, 2014
@roji roji Unit test to reproduce #179 bee2709
@roji roji added a commit to roji/Npgsql that referenced this issue Jul 25, 2014
@roji roji Fix CommandBuilder event registration
CommandBuilder wasn't properly registering to its DataAdapter
events, resulting in bug #179
9940744
@roji
Npgsql member

@czarnul, @neonsnowball, this bug has been fixed in master. You can download the latest binaries from our build server and confirm.

@roji roji closed this Jul 26, 2014
@roji roji added a commit that referenced this issue Jul 26, 2014
@roji roji Unit test to reproduce #179
(cherry picked from commit bee2709)

(From #294)
d389f71
@roji roji added a commit that referenced this issue Jul 26, 2014
@roji roji Fix CommandBuilder event registration
CommandBuilder wasn't properly registering to its DataAdapter
events, resulting in bug #179

(cherry picked from commit 9940744)

(From #294)
8678469
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment