Tuesday, March 20, 2012

save unicode data into MSDE SQL

Dear Expert:

I am facing a problem which is after the Asia characters saving to SQL server (MSDE version), value in the field will be showed in all question marks, the develop enviroment which I used is Visual Studio .Net 2003 C# and in Windows XP Sp2, the system is already configured to Unicode, I have also set the field type in database is nVarChart, when I manually key in these Asia characters into the database, it shows the correct word, when through the application, the problem will be happened.

Any reply is a very appreciate.

Wells.

How do you insert the data into the database, could you show us some code ?

HTH, Jens Suessmeyer.

|||

I'm facing similar problem.

The problem is the MSDE and the application is using different code page.

The complete code page can be found in: http://msdn.microsoft.com/library/?url=/library/en-us/intl/unicode_81rn.asp

MSDE may store data using Unicode UCS-2 (cp=1200 or 1201) or Unicode UTF-8 (cp=65001).

How I can check the code page of the current MSDE database is using?

While the application (in your case is Vs.net, in my case is MsAccess) is different code page. The only 2 cp supported in MsAccess are :

dbLangChineseSimplified = ";LANGID=0x0804;CP=936;COUNTRY=0"|||

Hi Jens,

Thanks for you reply, the followed codes are the details of insert a record into the SQL database, hope that will give clues to solve my problem.

public string Add(string userid, string password, string email, string firstName,

string lastName, string address1, string address2,

string city, string state, string zip, string country,

string phone, string languagePref, string favoriteCategory,

int mylistOption, int bannerOptions) {

// create data object and params

Database data = new Database();

SqlParameter[] prams = {

data.MakeInParam("@.userid", SqlDbType.VarChar, 80, userid),

data.MakeInParam("@.password", SqlDbType.VarChar, 25, password),

data.MakeInParam("@.email", SqlDbType.VarChar, 80, email),

data.MakeInParam("@.firstname", SqlDbType.nVarChar, 80, firstName),

data.MakeInParam("@.lastname", SqlDbType.nVarChar, 80, lastName),

data.MakeInParam("@.addr1", SqlDbType.nVarChar, 80, address1),

data.MakeInParam("@.addr2", SqlDbType.nVarChar, 80, address2),

data.MakeInParam("@.city", SqlDbType.nVarChar, 80, city),

data.MakeInParam("@.state", SqlDbType.VarChar, 20, state),

data.MakeInParam("@.zip", SqlDbType.VarChar, 20, zip),

data.MakeInParam("@.country", SqlDbType.nVarChar, 80, country),

data.MakeInParam("@.phone", SqlDbType.VarChar, 80, phone),

data.MakeInParam("@.langpref", SqlDbType.nVarChar, 25, languagePref),

data.MakeInParam("@.favcategory", SqlDbType.VarChar, 25, favoriteCategory),

data.MakeInParam("@.mylistopt", SqlDbType.Int, 4, mylistOption),

data.MakeInParam("@.banneropt", SqlDbType.Int, 4, bannerOptions)

};

try {

// run the stored procedure and return an ADO.NET DataReader

int retval = data.RunProc("upAccountAdd", prams);

// if the customer id is an empty string, then the create failed

if (retval == 0 )

return userid;

else

return null;

}

catch (Exception ex) {

Error.Log(ex.ToString());

return null;

}

}

Thanks in advance for your any solution.

Wells.

|||

Shouldn't you be using SqlDbType.NVarChar, instead of SqlDbType.VarChar?

No comments:

Post a Comment