Does the SQL Server CE engine have to be told the commandtype is text if that should be obvious?

StackOverflow https://stackoverflow.com/questions/17977868

Вопрос

I've got this code:

using (SqlCeConnection sqlConn = new SqlCeConnection(@"Data Source=\my documents\\PlatypusDB.SDF"))
{
    sqlConn.Open();
    string dmlStr = "insert into platypus_settings (setting_name, setting_value) values(?, ?)";
    SqlCeCommand cmd = new SqlCeCommand(dmlStr, sqlConn);
    cmd.CommandType = CommandType.Text; //<-- necessary?
    cmd.Parameters[0].Value = settingName;
    cmd.Parameters[1].Value = settingVal;
    try
    {
        cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        Platypus.ExceptionHandler(ex, "writeSettingsVal");
    }
}

...but don't know if the commented line is needed, is bloatcode, or doesn't matter either way?

Это было полезно?

Решение

... but don't know if the commented line is needed

No. Not because it's obvious but because it happens to be the default.

From MSDN:

Property Value
One of the CommandType values. The default is Text.

Having said that, it certainly is not bloat-code and I might include it, just to make the code a little less ambigious to read.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top