我继承了一个旧的 Web 应用程序,它使用经典的 ASP 将以表单形式收集的数据写入 Access 2007 数据库。
现在他们需要它能够收集西里尔字母的输入。
我完全不熟悉代码页/字符集,也不熟悉非拉丁字母表。
我已经尝试将报名表页面上的字符集更改为 ISO-8859-1 ,它似乎确实存储了字符的 ascii 值(例如:#1076;)。因此,浏览器可以很好地解释和读取它,但是就将数据导出到 excel 以传递给需要它的部门而言,它几乎没有用。
所以我的问题是:
有没有一种简单的方法可以从 Web 表单中捕获西里尔字符并将它们作为西里尔字符插入到我的 Access 表中?
或者交替
access 数据库中是否有工具或设置可以将十进制值 (#1076;) 转换为 access 本身的西里尔字符。
最佳答案
如果您的页面坚持使用 UTF-8,它们应该可以工作(但请参阅下面的重要说明)。虽然 Access 确实不在内部将 Unicode 字符存储为 UTF-8,但 Access OLEDB 驱动程序将为您处理转换。
考虑以下示例脚本(其中 65001
是 UTF-8 的“代码页”):
<%@ CODEPAGE = 65001 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Classic ASP Unicode Test</title>
</head>
<body bgcolor="white" text="black">
<%
Dim con, cmd, rst
Const adVarWChar = 202
Const adParamInput = 1
Set con = CreateObject("ADODB.Connection")
con.Mode = 3 ' adModeReadWrite
con.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\_wwwdata\unicodeTest.mdb;"
If Len(Trim(Request.Form("word"))) > 0 Then
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandText = "INSERT INTO vocabulary (word, language, english_equiv) VALUES (?,?,?)"
cmd.Parameters.Append cmd.CreateParameter("?", adVarWChar, adParamInput, 255, Request.Form("word"))
cmd.Parameters.Append cmd.CreateParameter("?", adVarWChar, adParamInput, 255, Request.Form("language"))
cmd.Parameters.Append cmd.CreateParameter("?", adVarWChar, adParamInput, 255, Request.Form("english_equiv"))
cmd.Execute
Set cmd = Nothing
End If
%>
<h2>Word list:</h2>
<table border=1>
<tr>
<th>word</th><th>language</th><th>english_equiv</th>
</tr>
<%
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT * FROM vocabulary ORDER BY ID", _
con, 3, 3
Do Until rst.EOF
Response.Write "<tr>"
Response.Write "<td>" & rst("word").Value & "</td>"
Response.Write "<td>" & rst("language").Value & "</td>"
Response.Write "<td>" & rst("english_equiv").Value & "</td>"
Response.Write "</tr>"
rst.MoveNext
Loop
Response.Write "</table>"
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
%>
<h2>Add a new entry:</h2>
<form action="<% Response.Write Request.ServerVariables("SCRIPT_NAME") %>" method="POST">
<table>
<tr>
<td align="right">word:</td>
<td><input type="text" name="word"></td>
</tr>
<tr>
<td align="right">language:</td>
<td><input type="text" name="language"></td>
</tr>
<tr>
<td align="right">english_equiv:</td>
<td><input type="text" name="english_equiv"></td>
</tr>
<tr>
<td></td>
<td align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</body>
</html>
从 Access 数据库中名为 [vocabulary] 的表开始
当我们加载我们看到的 ASP 页面时
如果我们为俄语单词添加一个新条目
然后点击“提交”页面将刷新
如果我们在 Access 中检查表,我们会看到
重要提示
请注意,您不应将 Access 数据库用作 Web 应用程序的后端数据存储; Microsoft 强烈建议不要这样做(引用:here)。
关于ms-access - 捕获 Unicode 文本(西里尔文)并将其插入 MS Access 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22054934/