This time it is that I have a method to insert some values into the data base, and I want to be able to insert NULL values. But I can't find the way to do it.
This is my insert method
- Code: Select all
public void Insert(string sName, object oVal)
{
string sql = @"
INSERT INTO _params
(
name,
val
) VALUES
(
:name,
:val
)";
SqliteCommand cmd = new SqliteCommand(sql, mConn);
SqliteParameter param = new SqliteParameter();
param.ParameterName = ":name";
param.Value = sName;
cmd.Parameters.Add(param);
param = new SqliteParameter();
param.ParameterName = ":val";
param.Value = oVal;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
}
The table was created with
- Code: Select all
CREATE TABLE _params
(
name TEXT NOT NULL UNIQUE,
val TEXT
)
When I run this code I get a NullRefrenceException, if I try and insert a null. I have also tried to changing the line 'param.Value = oVal;' to
- Code: Select all
if (oVal == null)
param.Value = "NULL"; // also tried "\0" and ""
else
param.Value = oVal;
But the code either crashes or uses the value as a string and not a null value.
Can anyone help me insert NULL values via the Parameter object.