我從XML獲取「SystemID」的值。即我將值存儲在dictionary<string,string>,
中如果xml中沒有提供「SystemID」,即xml中不存在<SystemID></SystemID>
,我希望向DB發送null。向數據庫發送空值
這是我的代碼。但它不起作用。有任何想法嗎!
sqlCommand.Parameters.Add("@SystemID", SqlDbType.Int).Value = string.IsNullOrEmpty(attributeValues["systemID"]) ? (object)DBNull.Value : Convert.ToInt32(attributeValues["systemID"]);
你有什麼異常嗎? –
可能重複的[如何將null分配給sqlparameter?](http://stackoverflow.com/questions/4555935/how-to-assign-null-to-a-sqlparameter) – wudzik
'attributeValues'字典是否總是包含'systemID'鍵,即使它的值可能爲空? –