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