Multiple Insert not working...

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
dsaracini
Posts: 17
Joined: Wed 04 Mar 2009 07:50

Multiple Insert not working...

Post by dsaracini » Thu 19 Mar 2009 17:40

Hello,

The following fails to insert data into the tables. It DOES return the correct IDs (it just fails to actually populate the "names" - which is kind of important)

Code:

private void button1_Click(object sender, EventArgs e)
{
Conn.Open();
try
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("insert into foo (foo_name) values (:1) returning id;");
sb.AppendLine("insert into moo (moo_name) values (:2) returning id;");
sb.AppendLine("insert into foo (foo_name) values (:3) returning id;");
sb.AppendLine("insert into noo (noo_name) values (:4) returning id;");

PgSqlCommand cmd = new PgSqlCommand();
cmd.CommandText = sb.ToString();
cmd.Connection = Conn;

cmd.Parameters.Add(new PgSqlParameter("1", "Foo"));
cmd.Parameters.Add(new PgSqlParameter("2", "Moo"));
cmd.Parameters.Add(new PgSqlParameter("3", "Foo2"));
cmd.Parameters.Add(new PgSqlParameter("4", "Noo"));

StringBuilder sb2 = new StringBuilder();

using (PgSqlDataReader reader = cmd.ExecuteReader())
{
do
{
while (reader.Read())
{
sb2.AppendLine(reader.GetString(0));
}
}
while (reader.NextResult());
}

MessageBox.Show(sb2.ToString());
}
finally
{
Conn.Close();
}

}

Note: I'm using protocol 2; Postgres 8.3.4; Devart 4.0.22

I have to say that at this point, I'm getting pretty frustrated with Devart. I feel like everything I try to do other than just doing a simple "select" with no params FAILS.

May I inquire about your QA procedures? I feel like I"m doing your QA. Do you have unit tests for your components? It seems like all of this would be very simple to write unit tests for. Virtually everything is non-visual.

I'm afraid I'm going to have to give up on Devart and ask for refund and go with the freeware components. At least then I have the code and can fix the problems myself.

David

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 20 Mar 2009 14:02

Please replace the lines of your code

Code: Select all

cmd.Parameters.Add(new PgSqlParameter("1", "Foo"));
cmd.Parameters.Add(new PgSqlParameter("2", "Moo"));
cmd.Parameters.Add(new PgSqlParameter("3", "Foo2"));
cmd.Parameters.Add(new PgSqlParameter("4", "Noo"));
with the following lines

Code: Select all

cmd.Parameters.Add(new PgSqlParameter("1", (object)"Foo"));
cmd.Parameters.Add(new PgSqlParameter("2", (object)"Moo"));
cmd.Parameters.Add(new PgSqlParameter("3", (object)"Foo2"));
cmd.Parameters.Add(new PgSqlParameter("4", (object)"Noo"));
Please see the list of overloads of the PgSqlParameter constuctor. If the second parameter is "Foo" - it is recognized as [string rowTypeName]. If the second parameter is (object)"Foo" - it is recognized as [object value].

Post Reply