如何通过自定义分配ID?

时间:2013-12-05 08:51:11

标签: c# asp.net database textbox dataset

我有一个整数值id,它没关系,默认情况下它取值1,2,3 ......现在我想取这个值,如0001,0002,0003。怎么可能请帮助我。

 USE [Companybook]
    GO

    /****** Object:  Table [dbo].[Employees]    Script Date: 12/05/2013 14:50:14 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE TABLE [dbo].[Employees](
        [EmployeeID] [int] IDENTITY(1,1) NOT NULL,
        [LastName] [nchar](10) NULL,
        [FirstName] [nchar](10) NULL,
        [Country] [nchar](10) NULL,
     CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 
    (
        [EmployeeID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    GO

1 个答案:

答案 0 :(得分:0)

嗨,你不能在Sql中使用0001作为身份,而不是你可以使用有效数字,如1001,2001,3001 ......

但你可以像你说的那样检索你的身份......

请参考链接: http://social.msdn.microsoft.com/Forums/en-US/9ae39780-9e95-4e91-bd9f-9f9fc9232084/how-to-make-int-identity-field-showed-like-0001-

http://forums.asp.net/t/1625788.aspx