我收到錯誤:未能參數值從Int64類型轉換爲字節[]
Failed to convert parameter value from a Int64 to a Byte[].
下面是我在做什麼...
我有一個表在我的數據庫列:
sessionid | binary(32) | null
當我分配給它,我這樣做:
user.LastActivityDate = DateTime.Now;
user.SessionId = user.LastActivityDate.ToBinary();
的SessionID是從一個接口繼承的財產:
long? SessionId { get; set; }
這裏,它在我的User類被訪問:
[SettingsAllowAnonymous(false), CustomProviderData("SessionId;string")]
public long? SessionId { get { return base["SessionId"] as long?; } set { base["SessionId"] = value; } }
在我的自定義配置文件提供者,以下命令將值:
sqlCommand.Parameters.Add("sessionid", SqlDbType.Binary, 32).Value = settingsPropertyValue.PropertyValue;
當「sqlCommand.ExecuteNonQuery()」命令執行存儲的更新 過程與param ETER:
@sessionid binary(32)
,結果是錯誤:
"Failed to convert parameter value from a Int64 to a Byte[]."
我曾嘗試:
- ... = Convert.ToByte(settingsPropertyValue.PropertyValue);
- ... = Convert.ToInt64(settingsPropertyValue.PropertyValue);
任何想法?謝謝。
好的,謝謝。我試過sqlCommand.Parameters.Add(「sessionid」,SqlDbType.BigInt,sizeof(Int64))。Value = settingsPropertyValue.PropertyValue;並且得到「值對於無符號字節來說太大或太小」。這看起來不錯嗎? – 2010-01-18 22:54:21
SQL Server中它的數據類型是什麼? – SLaks 2010-01-18 23:04:56
sessionid |二進制(32)| null – 2010-01-18 23:07:42