469,913 Members | 2,443 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF."

How can I fix this? When I do the below I get the error message:

"Cannot insert explict value for identity column in table
'Employees' when IDENTITY_INSERT is set to OFF."

To get this message, I click the Add button to add a new row to the
database, and then I click the Update button to save the new database
to the external memory.

The methods I used are below.

Thanks,
Chris Lusardi

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim drNew As DataRow

drNew = dsAdoSbs.Employees.NewRow()
drNew.Item("FirstName") = "New First"
drNew.Item("LastName") = "New Last"
dsAdoSbs.Employees.Rows.Add(drNew)
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
daEmployees.Update(dsAdoSbs.Employees)
UpdateDisplay()
End Sub

May 17 '06 #1
6 6483
When I look at the properties of the data adapter for daEmployees
nothing jumps out at me?

Chris Lusardi

May 17 '06 #2
Christopher,

I would look in the database for the description of the key column

Just my thought,

Cor

"Christopher Lusardi" <cl********@aol.com> schreef in bericht
news:11**********************@i39g2000cwa.googlegr oups.com...
How can I fix this? When I do the below I get the error message:

"Cannot insert explict value for identity column in table
'Employees' when IDENTITY_INSERT is set to OFF."

To get this message, I click the Add button to add a new row to the
database, and then I click the Update button to save the new database
to the external memory.

The methods I used are below.

Thanks,
Chris Lusardi

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim drNew As DataRow

drNew = dsAdoSbs.Employees.NewRow()
drNew.Item("FirstName") = "New First"
drNew.Item("LastName") = "New Last"
dsAdoSbs.Employees.Rows.Add(drNew)
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
daEmployees.Update(dsAdoSbs.Employees)
UpdateDisplay()
End Sub

May 17 '06 #3

Cor Ligthert [MVP] wrote:
I would look in the database for the description of the key column


How do I do this? When I start vb and view "Server Explorer", I see:

- Data Connections
- chrislusardi\sqlexpress.AdoStepByStep.dbo
+ Database Diagrams
- Tables
- Employees
LastName
FirstName
...

I can't find "sqlexpress.AdoStepByStep" on my PC with a search on the C
drive.

Chris Lusardi

May 17 '06 #4

Christopher Lusardi wrote:
Cor Ligthert [MVP] wrote:
I would look in the database for the description of the key column


How do I do this? When I start vb and view "Server Explorer", I see:

- Data Connections
- chrislusardi\sqlexpress.AdoStepByStep.dbo
+ Database Diagrams
- Tables
- Employees
LastName
FirstName
...


With a I double click on Employees, I see a yellow light bulb next to a
column indicating it's the primary key column. When I click on that
yellow bulb, nothing in the properties jump out and say here's the
error.

Chris Lusardi

May 17 '06 #5
Christopher,

Can you download the SQLServer Express beta management tool. I have no
expirience with that but it is for sure better than the server explorer.

Cor

"Christopher Lusardi" <cl********@aol.com> schreef in bericht
news:11**********************@y43g2000cwc.googlegr oups.com...

Christopher Lusardi wrote:
Cor Ligthert [MVP] wrote:
> I would look in the database for the description of the key column


How do I do this? When I start vb and view "Server Explorer", I see:

- Data Connections
- chrislusardi\sqlexpress.AdoStepByStep.dbo
+ Database Diagrams
- Tables
- Employees
LastName
FirstName
...


With a I double click on Employees, I see a yellow light bulb next to a
column indicating it's the primary key column. When I click on that
yellow bulb, nothing in the properties jump out and say here's the
error.

Chris Lusardi

May 17 '06 #6
I would modify your data adapter to ensure the identity column is not part of
your insert statement.

The button click event is adding a row to your dataset, not the database.
So calling the 'Update' method is actually doing an insert (not an update) on
the row you added.
--
--ewok
MCSA+M,MCSE, MCSD, MCDBA,MCITP
"Christopher Lusardi" wrote:
How can I fix this? When I do the below I get the error message:

"Cannot insert explict value for identity column in table
'Employees' when IDENTITY_INSERT is set to OFF."

To get this message, I click the Add button to add a new row to the
database, and then I click the Update button to save the new database
to the external memory.

The methods I used are below.

Thanks,
Chris Lusardi

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim drNew As DataRow

drNew = dsAdoSbs.Employees.NewRow()
drNew.Item("FirstName") = "New First"
drNew.Item("LastName") = "New Last"
dsAdoSbs.Employees.Rows.Add(drNew)
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
daEmployees.Update(dsAdoSbs.Employees)
UpdateDisplay()
End Sub

Jun 1 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by isaacrajan | last post: by
2 posts views Thread by Tom Gao | last post: by
reply views Thread by Christopher | last post: by
3 posts views Thread by Fabio Negri Cicotti [MCP] | last post: by
8 posts views Thread by carlospedr | last post: by
3 posts views Thread by nicolas.bouchard | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.