SET IDENTITY_INSERT ON via C#

  • Thread starter Thread starter Mikael Syska
  • Start date Start date
M

Mikael Syska

Hi,

How can I set IDENTITY_INSERT to ON on the mssql server via C#, and turn
it OFF again, after I have made my insert?

Cause right now I can't sinde one of the Column's have IDENTITY on.

Kind Regards
Mikael Syska
 
Hi,

How can I set IDENTITY_INSERT to ON on the mssql server via C#, and turn
it OFF again, after I have made my insert?

Cause right now I can't sinde one of the Column's have IDENTITY on.

Assuming you're using SQL Server 2000, just place

SET IDENTITY_INSERT <tablename> ON

at the beginning of your SQL and

SET IDENTITY_INSERT <tablename> OFF

at the end
 
Kind a new to C#, how do I devide that???

if my SqlCommand look like this:
thisCommand = new SqlCommand("INSERT INTO [regGroups] VALUES (3, 'det
kan man godt', 'desc', 0, '10-10-2004 05:47:17')", thisConnection);
 
I just created a Stored Procedure........

Mikael said:
Kind a new to C#, how do I devide that???

if my SqlCommand look like this:
thisCommand = new SqlCommand("INSERT INTO [regGroups] VALUES (3, 'det
kan man godt', 'desc', 0, '10-10-2004 05:47:17')", thisConnection);


Mark said:
Assuming you're using SQL Server 2000, just place

SET IDENTITY_INSERT <tablename> ON

at the beginning of your SQL and

SET IDENTITY_INSERT <tablename> OFF

at the end
 
Mikael said:
Kind a new to C#, how do I devide that???

if my SqlCommand look like this:
thisCommand = new SqlCommand("INSERT INTO [regGroups] VALUES (3, 'det kan
man godt', 'desc', 0, '10-10-2004 05:47:17')", thisConnection);

new SqlCommand("SET IDENTITY_INSERT ON;INSERT INTO... ;SET IDENTITY_INSERT
OFF", ....);

Frans.
 
Back
Top