C# – DataGridView inserts primary key

cdatagridview

I'm trying to get a basic DataGridView to insert new rows into a table. The table has an auto incrementing primary key (Identity 1,1) and I'm having two problems with this.

The first problem is the DataSet which the DataGridView is populated from complains that the primary key in the row is null (I hide the primary key field from the DataGridView).

This problem disappears when I disable constrain checking or modify the DataSet to ignore the primary key being null.

The next problem is SQL Server complains about the DataSet trying to insert a value into the primary key field. It doesn't like it when the DataSet specifies the value for the primary key.

I'm very new to using C# and I've never used a DataGrid before.

Best Answer

The problem was the queries in the dataset were not being updated when I changed the properties of elements in the dataset. All I had to do was reconfigure the dataset.