61阅读

asp读取access数据库-asp.net读取数据库乱码的解决完全方案

发布时间:2017-11-15 所属栏目:mssql数据库

一 : asp.net读取数据库乱码的解决完全方案

在下面的映射表中加入gb2312 和gbk,就不会有乱码了,源码在下面提供一位网友写的程序改了改

private static void LoadCharsetMap()
{
mapping = new Hashtable();

mapping.Add( "big5", "big5" ); // Traditional Chinese
mapping.Add( "sjis", "sjis" ); // Shift-JIS
mapping.Add( "gb2312", "gb2312" );
mapping.Add( "latin1", "latin1" );
mapping.Add( "latin2", "latin2" );
mapping.Add( "latin3", "latin3" );
mapping.Add( "latin4", "latin4" );
mapping.Add( "latin5", "latin5" );
mapping.Add( "greek", "greek" );
mapping.Add( "hebrew", "hebrew" );
mapping.Add( "utf8", "utf-8" );
mapping.Add( "ucs2", "UTF-16BE" );
mapping.Add( "cp1251", 1251 );
mapping.Add( "tis620", 874 );
mapping.Add( "binary", "latin1" );

// relatively sure about
/**//* mapping.Add( "default", 0 );
mapping.Add( "cp1251", 1251 ); // Russian
mapping.Add( "win1251", 1251 );
mapping.Add( "gbk", 936 ); // Simplified Chinese
mapping.Add( "cp866", 866 );
mapping.Add( "euc_kr", 949 );

// maybe, maybe not
mapping.Add( "win1250", 1250 ); // Central Eurpoe
mapping.Add( "win1251ukr", 1251 );
mapping.Add( "latin1_de", 1252 ); // Latin1 German
mapping.Add( "german1", 1252 ); // German
mapping.Add( "danish", 1252 ); // Danish
mapping.Add( "dos", 437 ); // Dos
mapping.Add( "pclatin2", 852 );
mapping.Add( "win1250ch", 1250 );
mapping.Add( "cp1257", 1257 );
mapping.Add( "usa7", 646 );
mapping.Add( "czech", 912 );
mapping.Add( "hungarian", 912 );
mapping.Add( "croat", 912 ); */

/**//* ("gb2312", "EUC_CN");
("ujis", "EUC_JP");
("latvian", "ISO8859_13");
("latvian1", "ISO8859_13");
("estonia", "ISO8859_13");
("koi8_ru", "KOI8_R");
("tis620", "TIS620");
("macroman", "MacRoman");
("macce", "MacCentralEurope");
*/

}

二 : ASP 获取mssql数据库二进制数据

1. 保存至服务器中

<%

Dim id_srl  'request.QueryString("id_srl")

id_srl=49

if Cint(id_srl) >0 then

Dim Conn,ConnStr,Rs,Sql,MyStream

ConnStr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=fdp_user;Initial Catalog=FDP;Data Source=10.120.120.153;Locale     Identifier=1036;Connect Timeout=15;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;"

Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr,"fdp_user","rlxhamster"

Sql = "select * from srl_contenu where id_srl="& id_srl

Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,Conn,1,3

Set objStream=Server.CreateObject("Adodb.Stream")

objStream.Type = 1
objStream.Open
objStream.Write Rs("Contenu").GetChunk(rs("Contenu").ActualSize-78)
objStream.SaveToFile server.MapPath("db")& "\" & Rs("Nom_fichier"),2

Set fso=Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(server.MapPath("db")& "\" & Rs("Nom_fichier"))=True Then
response.write "File "& Rs("Nom_fichier") & " saved success!!"
end if

objStream.Close
set objStream=Nothing

Rs.Close
Set Rs = Nothing

Conn.Close
Set Conn = Nothing

end if

%>

 

2.下载文件示例

<%

'设置文件的大小及MIME类型
Function SetForDisplay(field, contentType)
  contentType = LCase(trim(contentType))
  nFieldSize = field.ActualSize
  bytes = field.GetChunk(nFieldSize)
  Session("Bytes") = bytes
  Session("Type") = contentType
End Function

Function SetFileSize(field)
  nFieldSize = field.ActualSize
  SetFileSize = field.GetChunk(nFieldSize)  
End Function

SetForDisplay rs("Contenu"),rs("Content_type")
Response.AddHeader "Content-Disposition", "attachment; filename=" & rs("Nom_fichier")
response.contentType = Session("Type")
response.BinaryWrite Session("Bytes")
Session("Type") = ""
Session("Bytes") = ""

%>

扩展:asp连接mssql数据库 / mssql 获取数据库表 / asp获取数据库数据

三 : 关于的免费asp空间这个空间支持access数据库吗?我上传了几

关于 的免费asp空间

这个空间支持access吗?
我上传了几个论坛都无法正常使用。自己做了个小asp文件上传后在浏览器打开居然显示:“您要访问的网页有问题,无法显示”

请大家指教。
谢谢。


数据库大小有限制

本文标题:asp读取access数据库-asp.net读取数据库乱码的解决完全方案
本文地址: http://www.61k.com/1060431.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1