I am using this database:
http://www.postgresqltutorial.com/postg ... -database/
I installed the database like this:
http://www.postgresqltutorial.com/load- ... -database/
I want to use PgSqlDataTable with the actor table.
Here is the DDL for the table:
Code: Select all
CREATE TABLE public.actor
(
actor_id integer NOT NULL DEFAULT nextval('actor_actor_id_seq'::regclass), -- serial
first_name character varying(45) NOT NULL,
last_name character varying(45) NOT NULL,
last_update timestamp without time zone NOT NULL DEFAULT now(),
CONSTRAINT actor_pkey PRIMARY KEY (actor_id)
);

On pgSqlDataTable1 I set:
Active = true
CachedUpdates = false;
On dataLink1 I set:
DataSource = pgSqlDataTable1
SelectCommand for pgSqlDataTable1:

InsertCommand for pgSqlDataTable1:

Both buttons on the form interact with the dataLink1:
Code: Select all
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Save_Click(object sender, EventArgs e)
{
dataLink1.EndEdit();
}
private void btn_New_Click(object sender, EventArgs e)
{
dataLink1.AddNew();
}
}
(actor_id doesn't allow nulls)

Why does it even throw that error? I am not using the actor_id column in my insert statement (InsertCommand) at all. The correct value is generated automatically by the database because of the nextval of the sequence (see DDL).
When I use the same insert statement with a tool like pgAdmin 4 I works:
