我继承了一个旧的Web应用程序,该应用程序使用经典的ASP将以表格形式收集的数据写入Access 2007数据库。
现在,他们需要它能够收集西里尔字母的输入。
我完全不熟悉代码页/字符集,并且使用非拉丁字母。
我尝试将输入表单页面上的字符集更改为ISO-8859-1,该字符集似乎确实存储了字符的ascii值(例如:#1076;)。因此,可以由浏览器很好地解释和读取,但是在将数据导出到excel传递给需要它的部门方面几乎没有用。
所以我的问题是:
有没有一种简单的方法可以从Web表单捕获西里尔字母并将其作为西里尔字母插入到我的访问表中?
或交替
访问数据库中是否有工具或设置可以将十进制值(#1076;)转换为访问本身内的西里尔字符。
如果您坚持使用UTF-8作为页面,它们应该可以工作(但请参见下面的重要说明)。虽然这是事实,访问并没有在内部存储Unicode字符为UTF-8的访问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强烈建议您不要这样做(参考:此处)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句