我正在編寫一個部署在SQL Server 2008 R2(如.Net 3.5)上的C#存儲過程,並且希望聲明一個可選參數作爲可以爲空的guid。這是我第一次嘗試:如何使用SQL Server將可空的guid聲明爲C#CLR存儲過程的可選參數
這失敗,編譯時錯誤:
Default parameter value for 'sID' must be a compile-time constant
這是因爲DBNull.Value
不是一個常量,這是一種痛苦。
所以我試圖改變聲明:
[Microsoft.SqlServer.Server.SqlProcedure]
public static void spCalcPerc(
SqlGuid pID
, Guid? sID = null
)
這編譯,但現在我得到這樣的部署錯誤:
Deploy error : Could not create a type for parameter System.Nullable
嘗試:
, SqlGuid sID = null
給出了這樣的編譯時錯誤:
A value of type '< null >' cannot be used as a default parameter because there are no standard conversions to type 'System.Data.SqlTypes.SqlGuid'
所以感覺比較粘我使出這樣的:
, SqlGuid sID = "00000000-0000-0000-0000-000000000000"
但我並不想這樣做,以測試的代碼串感覺就像一個雜牌。但是這並不工作,如我得到這個編譯錯誤:
A value of type 'string' cannot be used as a default parameter because there are no standard conversions to type 'System.Guid'
爾加,4種不同的方法,沒有的他們的工作。 嘆息
請感謝您的想法或推動正確的方向請。
你有沒有嘗試過「Guid?sID」,沒有= null? – H27studio