Here is an example of using OleDbCommand and ExecuteNonQuery(I took it from a manual on msdn.microsoft.com). I would like to check out the query that was generated before executing it.
private static void OleDbCommandPrepare(string connectionString)
{
using (OleDbConnection connection = new
OleDbConnection(connectionString))
{
connection.Open();
// Create the Command.
OleDbCommand command = new OleDbCommand();
// Set the Connection, CommandText and Parameters.
command.Connection = connection;
command.CommandText =
"INSERT INTO dbo.Region (RegionID, RegionDescription) VALUES (?, ?)";
command.Parameters.Add("RegionID", OleDbType.Integer, 4);
command.Parameters.Add("RegionDescription", OleDbType.VarWChar, 50);
command.Parameters[0].Value = 20;
command.Parameters[1].Value = "First Region";
// Call Prepare and ExecuteNonQuery.
command.Prepare();
find out the query that is being executed here
command.ExecuteNonQuery();
// Change parameter values and call ExecuteNonQuery.
command.Parameters[0].Value = 21;
command.Parameters[1].Value = "SecondRegion";
command.ExecuteNonQuery();
}
}
Is there any possible way to do it? I'm using PgSqlCommand - which is PostgreSQL equivalent of OleDbCommand and getting undescribed exception. I was able to build that query and find what was the error by cycling Command.Parameters and replacing question symbols in Command.CommandText with paremeter's values, but I am hoping that there is a built-in method to get that query.