First off, I like specifying data types and I despise AddWithValue functions.
I’m building an SqlCeServer 3.5 local database Application under .NET 4.0 that will run on users PC.
When I created the table, I use NVarChar(50) to specify my string fields.
This seems to work fine, and I can open the table to verify everything worked well in Microsoft SQL Server Management Studio 2008.
When I insert data into my tables, I use
public static SqlCeParameter ParameterString(string ColumnName, string value) {
SqlCeParameter p = new SqlCeParameter();
p.ParameterName = string.Format("@{0}", ColumnName);
p.DataType = DbType.String;
p.Size = 50;
p.Value = value;
return p;
}
When I insert this data, there are no errors, but the data is not inserted. Other data types (int, DateTime, float, etc.) are inserting with no problems.
Q: Is there some other DbType I need to specify to insert as NVarChar?
The
DbTypeenum is generic for all databases, so it doesn’t contain all data types specific for SQL Server. Use anSqlDbType: