2017-08-24 35 views
0

我是ASP.NET新手,我正在學習一個教程來創建一個登錄頁面。但是,從nchar(10)切換到uniqueidentifier甚至將字符限制增加到50時,我無法更新表格,也無法保存它。這是我收到的錯誤下面誰能幫我解決這個問題?Visual Studio SQL Server表不更新

CREATE TABLE [dbo].[Table] 
(
    [Id]  UNIQUEIDENTIFIER NULL, 
    [Username] NCHAR (20) NULL, 
    [Password] NCHAR (20) NULL, 
    [Email] NCHAR (50) NULL, 
    [Country] NCHAR (20) NULL 
); 

改變[DBO] [表] ...

錯誤:

SQL72014: .Net SqlClient Data Provider:
Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.

SQL72045: Script execution error. The executed script:
ALTER TABLE [dbo].[Table] ALTER COLUMN [Id] UNIQUEIDENTIFIER NULL;

An error occurred while the batch was being executed.

+0

數據類型不匹配。使用Guid數據類型作爲C#中與sql中的Id相對應的屬性 – NoSaidTheCompiler

+0

當您調試時,您嘗試更新的ID列的值是多少? – Seano666

+0

嘗試將Guid.NewGuid()傳遞給您的ID,但我不建議這樣做,因爲您可以從Sql更改您的Id屬性。將RowGuid屬性設置爲true ..然後在創建時不必從ASP.NET傳遞一個ID –

回答

-1

嘗試用

(
[Id] DEFAULT NEWSEQUENTIALID() 
... 
) 
+0

您能否解釋'NEWSEQUENTIALID'如何解決問題? – Nisarg

+0

[NEWSEQUENTIALID()](https://msdn.microsoft.com/en-us/library/ms189786(v = sql.110).aspx) –