472,354 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 6586
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: isaacrajan | last post by:
Hello, How do I get SQL server 2000 to continue the sequence of identity column values after I perform an insert into the table with the set identity_insert <table name> on statement? Eg if I...
2
by: Tom Gao | last post by:
I have a problem. The project that I'm working on requires me to duplicate records. As in a series of records are entered into the system the user then click on a button to make these as...
1
by: Bharat | last post by:
I'm a bit new to SQL Server, but here is the problem I am trying to get around: 1. I have lets say an Employee table where the emp_id is an identity column that is auto assigned by the db. 2. I...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
0
by: Christopher | last post by:
I AM GETTING A SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION ERROR WHEN ATTEMPTING TO INSERT DATA INTO A SINGLE TABLE THROUGH A GRID //If this is due to a spelling error, i will //inflict a ritual...
3
by: Fabio Negri Cicotti [MCP] | last post by:
Hi All. I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's SetParentRow method. The parent table has an identity column as primary key. When I execute the code below I...
8
by: carlospedr | last post by:
I have to insert data from about 30 tables into a single table (Users), to do so i used a cursor and a bit of dynamic sql, this should work fine if the tables have to do the select from had the...
3
by: nicolas.bouchard | last post by:
I am developing an integration process between two databases. One of them is a SQL Server 2000 and the other is using MSDE 2000. The integration process is done in C# (VS2003). The main database...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.