Home > Software engineering >  VB use ADO database operation, all the parts and the character encoding problem
VB use ADO database operation, all the parts and the character encoding problem

Time:09-27


 
Dim conn As New ADODB. Connection
Conn. The ConnectionString="Provider=Microsoft. Jet. The OLEDB. 4.0; The Data Source=C: \ ceshi. MDB; Persist Security Info=False "
'open database connection
Conn. Open
Dim the Execute As String
The Execute="XXX"
Conn. Execute the Execute
'close the database and release the database objects
Conn. Close
Set the conn=Nothing


So that in the Insert statement is utf-8 encoding of the string, ASP website open is full of noise, how to solve this problem, find a lot of genius to find the reason, how to use GBK code to save string, online wait for the answer

CodePudding user response:

Starting from the Access 2000 is a Unicode string, you can open the MDB, did the content inside the code,
Reading is also a Unicode string from the ADO, do not need to turn the intermediate code,
Garbled words is most likely your ASP to string output to the page code is wrong,
ASP page displays the code solution/ASP code set

CodePudding user response:


There is no this command GBK code directly

Or change the asp code simple point.

If can turn Unicode utf-8 or

 'Utf8 converted to Unicode 
The Public Function UTF8_Decode (ByVal s As String) As String
Dim lUtf8Size As Long
Dim sBuffer As String
Dim lBufferSize As Long
Dim lResult As Long
Dim (b) As Byte
If LenB (s) Then
On Error GoTo EndFunction
B=StrConv (s, vbFromUnicode)
LUtf8Size=UBound (b) + 1
On Error GoTo 0
'Set the buffer for the longest possible string i.e. for each byte is
'ANSI<=& amp; HFF, thus 1 unicode (2 bytes) for every utf-8 character.
LBufferSize lUtf8Size * 2=
SBuffer=String $(lBufferSize vbNullChar)
'Translate using code page 65001 (utf-8)
LResult=MultiByteToWideChar (CP_UTF8, 0, b (0), _
LUtf8Size, StrPtr (sBuffer), lBufferSize)
'the Trim result to actual length
If lResult Then
UTF8_Decode=Left $(sBuffer lResult)
'the Debug. Print UTF8_Decode
End the If
End the If
EndFunction:
End the Function
  • Related