I am attempting to insert into a remote PostgreSqL database as a novice.

I am using C# 2008 Express, on Windows 7.

I have made a connection through a connection string which works well.

So far I have this code placed after the connection code.

string insertString = @"Insert into p_id.image (logothe_geom, description, text_)"
+ " select st_centroid (graphics.utilities_dgm.the_geom), ('Logo'), ('PDW')"
+ " From graphics.utilities_dgm"
+ " Where graphics.utilities_dgm.utilities_description = 'Base'";

SqlCommand command = new SqlCommand(insertString);

This gave me a "Conection property has not been initialized" error.

After a search I attempted to initialize the connection property by adding connectionString to the SQLCommand -
SqlCommand command = new SqlCommand(insertString, connectionString);

But this gives me an error about overloaded method match and invalid arguments.

Any help would be appreciated.


Edited 5 Years Ago by BobPawley: n/a

Assumming you have an open connection called PostgreSqLConnection to the server, you need to pass it as the second parameter, not the connection string.

SqlCommand command = new SqlCommand(insertString, PostgreSqLConnection)

In your insertString you have an insert sentence AND a select, so the command will return data. You are lying if you say that this is a non query.

I would suggest to separate both sentences in 2 separated commands.

Hope this helps

This article has been dead for over six months. Start a new discussion instead.