Cannot "Insert" Chinese Char

  • Thread starter Thread starter hao
  • Start date Start date
H

hao

Hi, all

When I use ASP to insert an record to a database, I got
some errors and can not insert any value with Chinese Char.
The only way I can do that is use "rst1.Addnew...rst1.update".
Anyone know why?


thx

hao
 
Hi Jerry,

If I use "INSERT INTO ...", the error message is :
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query
expression '''. /oa/send.asp, line 199


If I use "response.write" to track the sql string, I found the string was
terminated by the first of the Chinese Char(no Chinese Char can be read)
like this:

The Original SQL string:
INSERT INTO Table1(Field1, Field 2) VALUE('" & FieldValue1 & "', '" &
MyChineseWords & "')"

I got this result:
INSERT INTO Table1(Field1, Field 2) VALUE('abc', '

which the second field is my Chinese Char. No idea why the string
terminated.


If I use "rs.AddNew...." no error message and only a null value saved in the
table. I use "response.write" to
track the value before save to the table, it's still empty.

Lokks like the value MyChineseWords has some symbol and the system think
it's the end of string. I get MyChineseWords from a text form area that
input by user. There is no problem which English Charactor, only in Chinese.


hao
 
The database I used is Access and I know if I use SQL Server, I should add a
'N' before it
to indicate the unicode. But I do not know how to do in Access. Seems the
'N' does not work
in Access.


hao
 
I've never worked with Access, so I'm not sure if it even supports Unicode
strings but my suggestion would be to use Command object and add your
strings as parameters, like this (I suppose the space between Field and 2
and using VALUE instead of VALUES were just typos in your other post):

dbCmd.CommandText = "INSERT INTO Table1(Field1, Field2) VALUES(?, ?)";

dbCmd.Parameters.Add("@Field1", FieldValue1);
dbCmd.Parameters.Add("@Field2", YourChineseWords);

dbCmd.ExecuteNonQuery();

If that doesn't work then Access doesn't support Unicode as it is. In that
case you might have to encode your Unicode strings to UTF-8 before inserting
and remembering to decode them when reading.

Jerry
 
Back
Top