System.Data.IDbConnection conn = null; try { conn = com.janoserdelyi.DataSource.ConnectionManager.GetConnection("Nagry"); Npgsql.NpgsqlCommand command = new NpgsqlCommand("insert into article (article_title, article_desc, article_content, active, publish_dt, expire_dt, allow_comments, create_dt, create_author_id, categories) values (:articleTitle, :articleDesc, :articleContent, :active, :publishDt, :expireDt, :allowComments, :createDt, :createAuthorId, :categories); select lastval();", (Npgsql.NpgsqlConnection)conn); com.janoserdelyi.DataSource.CommandHelperFactory chf = new com.janoserdelyi.DataSource.CommandHelperFactory(DataSource.DatabaseType.Postgresql); com.janoserdelyi.DataSource.ICommandHelper commandHelper = chf.GetHelper(); commandHelper.Command = command; commandHelper.Append("articleTitle", articleTitle, 100); commandHelper.Append("articleDesc", articleDesc, 300); commandHelper.AppendText("articleContent", articleContent); commandHelper.Append("active", active); commandHelper.Append("publishDt", publishDt); commandHelper.Append("expireDt", expireDt); commandHelper.Append("allowComments", allowComments); commandHelper.Append("createDt", DateTime.Now); commandHelper.Append("createAuthorId", createAuthorId); commandHelper.Append("categories", categories); try { return command.ExecuteScalar(); } catch (Exception oops) { throw new Exception( "Insert failed to return scalar value. " + oops.Message); } } catch (Npgsql.NpgsqlException) { throw; } catch (System.Exception) { throw; } finally { try { com.janoserdelyi.DataSource.ConnectionManager.Close(conn); } catch {} }