I am trying to insert some data into an SQL Compact Edition table using a parameter. My table allows me to enter null, but when I run my code below, I cannot get it to work, because one of these parameters will sometimes be empty, and I would like to insert zero in this column when the parameter is null.
How can i fix this?
string strConn = Properties.Settings.Default.SqlConnectionString; using (SqlCeConnection conn = new SqlCeConnection(strConn)) { conn.Open(); using (SqlCeCommand cmd = new SqlCeCommand("insert into table(ID, Name, Adress) values (@parm1, @parm2, @param3)", conn)) { cmd.Parameters.AddWithValue("@parm1", ID); cmd.Parameters.AddWithValue("@parm2", Name); cmd.Parameters.AddWithValue("@parm3", Adress); cmd.ExecuteNonQuery(); } }
source share