I want to save in my DB unicode strings
i.e. “Content” below. How can I do this?
using (DbCommand objCMD = objDB.GetStoredProcCommand("usp_InsertMessage"))
{
objDB.AddInParameter(objCMD, "@Author", DbType.String, msg.Author);
objDB.AddInParameter(objCMD, "@Email", DbType.String, msg.Email);
objDB.AddInParameter(objCMD, "@Content", DbType.String, msg.Content);
objDB.AddInParameter(objCMD, "@Guid", DbType.Guid, msg.Guid);
try
{
objDB.ExecuteNonQuery(objCMD);
}
Since .NET uses Unicode for all its strings, this should be fine, IF your parameters like
@Authorand@Emailare defined asNVARCHAR(x)in your stored procedure, and if the columns you store that information into are also defined asNVARCHAR(x).So question is: are you seeing any problems?? If so: what are they??
As a sidenote: I would always define/specify a length for a string parameter. Not sure what that
AddInParametermethod does if you omit the length of the string parameter – often there will be a default, which may or may not be sufficient for you; so to avoid any unexpected surprises, I prefer to always explicitly define a max length for any string parameters.