提问人:MK01111000 提问时间:7/17/2023 最后编辑:MK01111000 更新时间:7/17/2023 访问量:73
在 Access 中加载字符时,字符替换为替换字符
Characters replaced with replacement character when loading characters in Access
问:
我在 VB.NET 代码中遇到了一个问题,即在将数据加载到我的应用程序中时,某些字符(例如“ü”)被替换为“替换字符”。
下面是代码片段的示例:
Dim adoConntestBks As New ADODB.Connection
adoConntestBks.ConnectionString = CommonAccessMethods.GetConnectionString(path_testBksDb)
adoConntestBks.Open()
strQuery = "INSERT INTO testBook ([ID],[testID],[LocaleID],[testBookPublisherID],[Description],[TitleHTML],[ColophonHTML],[TablOfContentJSON],[TableOfContentHTML]) " &
"VALUES (" & testBookID &
" ," & testID &
" ," & localeId &
" ," & currenttestBookPublisherID &
" ,'" & testBookDescription.Replace("'", "''") & "'" &
" ,'" & GetFirstFileFromFolder(path_activetestBks & nameOfFolder & "\title\", "*.html", True).Trim().Replace("'", "''") & "'" &
" ,'" & GetFirstFileFromFolder(path_activetestBks & nameOfFolder & "\colophon\", "*.html", True).Trim().Replace("'", "''") & "'" &
" ,'" & GetFirstFileFromFolder(path_activetestBks & nameOfFolder & "\toc\", "*.json", True).Trim().Replace("'", "''") & "'" &
" ,'" & GetFirstFileFromFolder(path_activetestBks & nameOfFolder & "\toc\", "*.html", False).Trim().Replace("'", "''") & "');"
adoConntestBks.Execute(strQuery)
在上面的代码中,我将值插入到使用 INSERT 语句调用的表中。
这些值是从各种源(包括文件内容)检索的。但是,当 json 文件中存在某些字符(如“ü”)时,在执行查询期间,它们将被替换为“替换字符”。
如何确保字符正确加载而不被替换字符替换?
任何帮助将不胜感激。testBook
我尝试使用命令参数来指定@Jimi建议的值的类型,但是特殊字符(如)仍被替换字符替换ü
Dim cmd As New ADODB.Command
cmd.ActiveConnection = adoConnTestBks
cmd.CommandText = "INSERT INTO TestBook ([ID],[TestID],[LocaleID],[TestBookPublisherID],[Description],[TitleHTML],[ColophonHTML],[TablOfContentJSON]) " &
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
cmd.Parameters.Append(cmd.CreateParameter("ID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, , TestBookID))
cmd.Parameters.Append(cmd.CreateParameter("TestID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, , TestID))
cmd.Parameters.Append(cmd.CreateParameter("LocaleID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, , localeId))
cmd.Parameters.Append(cmd.CreateParameter("TestBookPublisherID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, , currentTestBookPublisherID))
cmd.Parameters.Append(cmd.CreateParameter("Description", ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput, Len(TestBookDescription), TestBookDescription))
cmd.Parameters.Append(cmd.CreateParameter("TitleHTML", ADODB.DataTypeEnum.adLongVarChar, ADODB.ParameterDirectionEnum.adParamInput, Len(GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\title\", "*.html", True).Trim()), GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\title\", "*.html", True).Trim()))
cmd.Parameters.Append(cmd.CreateParameter("ColophonHTML", ADODB.DataTypeEnum.adLongVarChar, ADODB.ParameterDirectionEnum.adParamInput, Len(GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\colophon\", "*.html", True).Trim()), GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\colophon\", "*.html", True).Trim()))
cmd.Parameters.Append(cmd.CreateParameter("TablOfContentJSON", ADODB.DataTypeEnum.adLongVarChar, ADODB.ParameterDirectionEnum.adParamInput, Len(GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\toc\", "*.json", True).Trim()), GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\toc\", "*.json", True).Trim()))
'cmd.Parameters.Append(cmd.CreateParameter("TableOfContentHTML", ADODB.DataTypeEnum.adLongVarChar, ADODB.ParameterDirectionEnum.adParamInput, Len(GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\toc\", "*.html", False).Trim()), GetFirstFileFromFolder(path_activeTestBks & nameOfFolder & "\toc\", "*.html", False).Trim()))
cmd.Execute()
答: 暂无答案
评论
CharSet=utf8
adVarWChar
.Replace("'", "''")