SqlCeCommand nullable values
My code:
SqlCeConnection sql = new SqlCeConnection(@"Data Source=C:\DB.sdf");
sql.Open();
cmd = new SqlCeCommand("INSERT INTO xxx(aaa) VALUES(@aaa)", sql);
String param = null; //doesn't work
//String param = "blah" //works
cmd.Parameters.AddWithValue("@aaa", param);
cmd.ExecuteNonQuery(); //(1)
sql.Close();
(1) throws an exception when param
is null. Database allows value in collumn aaa
to be null. How can I insert null into table xxx ?
Exception:
Parameterized query 'INSERT INTO xxx(aaa) VALUES(@aaa)' expects a parameter value which w开发者_JAVA技巧as not supplied.
Try using DBNull.Value
instead:
var param = DBNull.Value;
Use
var param = DBNull.Value;
null isn't the same thing as DBNull
精彩评论