如何转换的UTF-8数据传统的ASP表单POST到UCS-2用于插入SQL Server 2008 R2的? [英] How do I convert UTF-8 data from Classic asp Form post to UCS-2 for inserting into SQL Server 2008 r2?

查看:268
本文介绍了如何转换的UTF-8数据传统的ASP表单POST到UCS-2用于插入SQL Server 2008 R2的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现代化,它使用访问一个传统的ASP应用程序的进程2000数据库。

I am in the process of "modernizing" a classic asp application that uses a Access 2000 database.

我改写的SQL Server 2008 R2上的数据库,并改变了所有的领域使用较新的UNI code启用的nchar,nvarchar的,NTEXT和进口的旧数据。我也是从IIS 6

I rewrote the database on SQL Server 2008r2 and changed all of the fields to use the newer unicode enabled nchar, nvarchar, ntext and imported the old data. I also switched to IIS 7 from IIS 6

经典的ASP是收集和使用UTF-8写入数据。

The classic asp is collecting and writing data using UTF-8.

现在应用程序正确显示旧数据的网页,但作为儿子,我抚摸它,即:更新或插入数据越来越损坏。我想我需要以某种方式为UTF-8的数据从传统的ASP到UCS-2转换不知何故之前,我写数据到SQL Server。

Now the application shows the OLD data correctly in the web pages but as son as I touch it ie: UPDATE or INSERT the data is getting corrupted. I assume I need to somehow convert the UTF-8 data from the classic asp to UCS-2 somehow before I write the data into SQL server.

但如何?

请注意:看来,SQL Server的自动转换为UTF-8数据转换成可用的格式,当它从访问导入的数据

NOTE: it seems that sql server auto converted the utf-8 data into a usable format when it imported the data from access.

推荐答案

您必须告诉SQL Server 2008中,你在UNI code数据通过添加N至您的插入值前发送。所以它是这样

You have to tell SQL Server 2008 that you are sending in unicode data by adding an N to the front of your insert value. so its like this

strTest = "Служба мгновенных сообщений"
strSQL = "INSERT INTO tblTest (test) VALUES (N'"&strTest&"')"

N个告诉SQL Server把内容作为统一code。而不会损坏数据。

The N tells SQL server to treat the Contents as Unicode. and does not corrupt the data.

请参阅 http://support.microsoft.com/kb/239530 询问。

下面是经典的ASP IIS 7 SQL Server上试code运行2008R2

Here is test code Run on Classic ASP IIS 7 SQL Server 2008r2

CREATE TABLE [dbo].[tblTest](
    [test] [nvarchar](255) NULL,
    [id] [int] IDENTITY(1,1) NOT NULL

ASP页

<%

Response.CodePage = 65001
Response.CharSet = "utf-8" 

strTest = Request("Test")

Set cnn = Server.CreateObject("ADODB.Connection")
strConnectionString = Application("DBConnStr")
cnn.Open strConnectionString



strSQL = "INSERT INTO tblTest (test) VALUES (N'"&strTest&"')"
Set rsData = cnn.Execute(strSQL)

%>
 <html xmlns="http://www.w3.org/1999/xhtml" charset="utf-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title></title>

</head 
<body>
    <form action="test.asp" method="post" name="form1" >
        <br/><br/><br/><center>
<table border="1">
    <tr><td><b>Test SQL Write</b> </td></tr>
    <tr><td><input type="text" name="Test" style="width: 142px" Value="<%=strtext%>" /></td></tr>
    <tr><td><input type="Submit" value="Submit" name "Submit" /></td></tr></table> </center>
</form>


</body>
</html>

这篇关于如何转换的UTF-8数据传统的ASP表单POST到UCS-2用于插入SQL Server 2008 R2的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆