您必須通過在插入值的前面添加N來告訴SQL Server 2008您以unicode數據發送數據。所以它是這樣
strTest = "Служба мгновенных сообщений"
strSQL = "INSERT INTO tblTest (test) VALUES (N'"&strTest&"')"
N個告訴SQL服務器來處理內容爲Unicode。並且不會破壞數據。
有關更多信息,請參閱http://support.microsoft.com/kb/239530。
下面是測試代碼經典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>