I have the following code that inserts some data into an Access table. It starts with a comma-separated string, which I split into a string array, and then add the elements of the array as parameters:
string line = "one\ttwo\t\tfour"; string[] values = line.Split('\t'); using (OleDbCommand com = new OleDbCommand("INSERT INTO [MyTable] (" + "[Field1], [Field2], [Field3], [Field4] " ") VALUES (" + "?, ?, ?, ?" + ")", con)) { com.Parameters.Add("@p0", OleDbType.Char, 255).Value = (object)values[0] ?? DBNull.Value; com.Parameters.Add("@p1", OleDbType.Char, 255).Value = (object)values[1] ?? DBNull.Value; com.Parameters.Add("@p2", OleDbType.Char, 255).Value = (object)values[2] ?? DBNull.Value; com.Parameters.Add("@p3", OleDbType.Char, 255).Value = (object)values[3] ?? DBNull.Value; com.ExecuteNonQuery(); }
In the above example, @p2 will not matter. It is entered into the Access table as a null value instead of a null value. At least I think I'm explaining it right. If I request Field3 is Null , I get no results. If I request Field3 = "" , I get the results. Does it mean empty or empty? Is there a "preferred" option?
Thanks!
source share