I'm trying to insert data to a table with a sequence to generate an ID automatically. Table and Sequence
CREATE TABLE [dbo].[Hotel] (
[HotelId] VARCHAR (50) NOT NULL,
[HotalName] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([HotelId] ASC)
);
GO
CREATE SEQUENCE dbo.IDSeq AS
INT START WITH 1
INCREMENT BY 1 ;
GO
ALTER TABLE dbo.Hotel
ADD CONSTRAINT Const_HotelId_Seq
DEFAULT FORMAT((NEXT VALUE FOR dbo.IDSeq),'HO-0000#') FOR HotelId;
GO
I tried to insert data in 2 different ways,
Method 1 (Working method)
INSERT INTO Hotel([HotelName]) VALUES ('Shangrilla')
Method 2(Not working)
DataClassesDataContext dc = new DataClassesDataContext ();
dc.Hotels.InsertOnSubmit(hotel);
dc.SubmitChanges();
dc.Dispose();
Data insertion is not working on code. How may I fix this?