SQL与access的转化问题,100分(100分)

  • 主题发起人 主题发起人 江北
  • 开始时间 开始时间

江北

Unregistered / Unconfirmed
GUEST, unregistred user!
我有个程序,是sql的,现在需要转化为access,数据库我已经转化成功了,但连接数据库的文件不知道怎么修改,代码如下,哪位高人帮忙解决
PS:个人认为不是修改那个连接的地方那么简单,因为我试过,没有成功,希望能把修改完后的的代码完整的发一遍,谢谢
<Script language="VBScript" runat="server">
Class DataBase ' 操作数据库对象
Public DatabaseConnectionString '//定义连接字符串
Public Conn '//定义连接对象
Public Rs '//定义记录集
'//实例化对象初始化
Private Sub Class_Initialize
On Error Resume Next
DatabaseConnectionString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=data;User ID=sa;
Password=123 ;server=10.0.0.6"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open DatabaseConnectionString
If Err.Number <> 0 then
Response.write "!!!!!!数据库链接出错!!!!!!请联系管理员!"
Response.End()
End If
End Sub
' //查询记录总数
Public Function RecordCount(Sql)
On Error Resume Next
Dim CountNum,Rs1
Set Rs1 = Server.CreateObject("ADODB.Recordset")
Rs1.Open Sql,Conn,1,1
If Not Rs1.Eof then
CountNum = Rs1.RecordCount
Rs1.close
If CountNum > 0 then
RecordCount = CountNum
else
RecordCount = 0
End If
else
RecordCount = 0
End If
If Err.Number <> 0 then
Err.Clear()
End Function
' //执行sql语句
Public Function RunSql(sql)
On Error Resume Next
Conn.Execute(Sql)
If Err.Number <> 0 then
RunSql = False
else
RunSql = True
End If
End Function
' //返回记录集
Public Function GetRecordSet(Sql)
On Error Resume Next
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,Conn,3,1
GetRecordSet = Rs
If Err.Number <> 0 then
Err.Clear()
End Function
'//Rs分页
Function ExportPageInfo(ByRef rs,curpage,i,LinkFile)
Dim retval, j, pageNumber, BasePage
retval = "第" &amp;
curpage &amp;
"页/总" &amp;
rs.pagecount &amp;
"页 "
retval = retval &amp;
"本页" &amp;
i &amp;
"条/总" &amp;
rs.recordcount &amp;
"条 "
If curpage = 1 then

retval = retval &amp;
"首页 前页 "
else

retval = retval &amp;
"<a href='" &amp;
LinkFile &amp;
"Page=1'>首页</a> <a href='" &amp;
LinkFile &amp;
"Page=" &amp;
cstr(curpage - 1) &amp;
"'>前页</a> "
End If
If curpage = rs.pagecount then

retval = retval &amp;
"后页 末页"
else
retval = retval &amp;
"<a href='" &amp;
LinkFile &amp;
"Page=" &amp;
cstr(curpage + 1) &amp;
"'>后页</a> <a href='" &amp;
LinkFile &amp;
"Page=" &amp;
cstr(rs.pagecount) &amp;
"'>末页</a>"
End if

retval = retval &amp;
"<br>"
BasePage = (curpage / 10) * 10
If BasePage > 0 then
retval = retval &amp;
" <a href='" &amp;
LinkFile &amp;
"Page=" &amp;
(BasePage - 9) &amp;
"'>&amp;lt;&amp;lt;</a>"
For j = 1 to 10
pageNumber = BasePage + j
If PageNumber > rs.pagecount then
Exit For
If pageNumber = Cint(curpage) then
retval = retval &amp;
" <font color='#FF0000'>" &amp;
pageNumber &amp;
"</font>"
else
retval = retval &amp;
" <a href='" &amp;
LinkFile &amp;
"Page=" &amp;
pageNumber &amp;
"'>" &amp;
pageNumber &amp;
"</a>"
End If
Next
If rs.pagecount > BasePage then
retval = retval &amp;
" <a href='" &amp;
LinkFile &amp;
"Page=" &amp;
(BasePage + 11) &amp;
"'>&amp;gt;&amp;gt;</a>"

ExportPageInfo = retval
End Function
'//实例化对象终止
Private Sub Class_Terminate
Set Rs = Nothing
Set Conn = Nothing
End Sub
End Class
Class StringObject '字符串对象
'//实例化对象初始化
Private Sub Class_Initialize
End Sub
'//实例化对象终止
Private Sub Class_Terminate
End Sub
Rem 过滤SQL非法字符
function checkSql(str)
if isnull(str) then
checksql = ""
exit function
end if
checksql=replace(str,"'","''")
end function
'//检测字符是否在什么的范围内
Public Function IsValidRegExp(str,Patrn)
Dim Re
Set Re = New RegExp
Re.Pattern = Patrn
Re.IgnoreCase = True
IsValidRegExp = Re.Test(str)
End Function
'//检测字段是否为空值
Public Function IsFieldNull(fstring)
Dim Flag
Flag = True
If (Not IsEmpty(fstring)) and (Len(trim(fstring)) > 0) then
Flag = False
End If
IsFieldNull = Flag
End Function
'//出现错误窗口
Public Sub Error(Fstring)
Response.write("<table width=510 height=255 border=0 align=center cellpadding=4 cellspacing=2 background=/pic/Error.gif bgcolor=efefef>")
Response.Write("<tr>")
Response.write("<td height=22 align=center></td>")
Response.Write("</tr>")
Response.write("<tr>")
Response.Write("<td height=140 valign=top style=""font-size:14px"">" + Fstring + "</td>")
Response.write("</tr>")
Response.write("<tr>")
Response.write("<td height=22 align=center>")
Response.Write("<a href=""Javascript:history.back()"" style=""text-decoration: none"" style=""font-size:14px""><font color=#FFFFFF><b>返回前页</b></font></a>")
Response.Write("&amp;nbsp;&amp;nbsp;&amp;nbsp;")
Response.Write("<a href=""Javascript:self.close()"" style=""text-decoration: none"" style=""font-size:14px""><font color=#FFFFFF><b>关闭窗口</b></font></a>")
Response.Write("</td>")
Response.write("</tr>")
Response.Write("</table>")
Response.End()
End Sub
'//取出N个字符串
Public Function LeftString(Fstring,N)
If Len(Fstring) > N then
Fstring = Left(Fstring,N)
End If
LeftString = Fstring
End Function
'//ubb代码
Public function UBBCode(strContent)
strContent =HtmlAn(strContent)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="(/[IMG/])(/S+?)(/[//IMG/])"
strContent=re.Replace(strContent,"<IMG SRC=""$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333"">")
re.Pattern="(/[FLASH/])(.+?)(/[//FLASH/])"
strContent= re.Replace(strContent,"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$2""><PARAM NAME=quality VALUE=high><embed src=""$2"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$2</embed></OBJECT>")
re.Pattern="(/[URL/])(/S+?)(/[//URL/])"
strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$2</A>")
re.Pattern="(/)(.+?)(/[//URL/])"
strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$3</A>")
re.Pattern="(/[EMAIL/])(/S+/@/S+?)(/[//EMAIL/])"
strContent= re.Replace(strContent,"<img align=absmiddle src=pic/email1.gif><A HREF=""mailto:$2"">$2</A>")
re.Pattern="(/[EMAIL=(/S+/@/S+?)/])(.+?)(/[//EMAIL/])"
strContent= re.Replace(strContent,"<img align=absmiddle src=pic/email1.gif><A HREF=""mailto:$2"" TARGET=_blank>$3</A>")
re.Pattern = "^(http://[A-Za-z0-9/./=/?%/-&amp;_~`@':+!]+)"
strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif><a target=_blank href=$1>$1</a>")
re.Pattern = "(http://[A-Za-z0-9/./=/?%/-&amp;_~`@':+!]+)$"
strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif><a target=_blank href=$1>$1</a>")
re.Pattern = "[^>=""](http://[A-Za-z0-9/./=/?%/-&amp;_~`@':+!]+)"

re.Pattern="(/[color=(.+?)/])(.+?)(/[//color/])"
strContent=re.Replace(strContent,"<font color=$2 style=""font-size:"&amp;FontSize&amp;"pt;line-height:"&amp;FontHeight&amp;"pt"">$3</font>")
re.Pattern="(/[face=(.+?)/])(.+?)(/[//face/])"
strContent=re.Replace(strContent,"<font face=$2 style=""font-size:"&amp;FontSize&amp;"pt;line-height:"&amp;FontHeight&amp;"pt"">$3</font>")
re.Pattern="(/[align=(.+?)/])(.+?)(/[//align/])"
strContent=re.Replace(strContent,"<div align=$2>$3</div>")
re.Pattern="(/[QUOTE/])(.+?)(/[//QUOTE/])"
strContent=re.Replace(strContent,"<table cellpadding=0 cellspacing=0 border=0 WIDTH=94% bgcolor=#000000 align=center><tr><td><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD BGCOLOR='"&amp;abgcolor&amp;"'>$2</table></table><br>")
re.Pattern="(/[fly/])(.+?)(/[//fly/])"
strContent=re.Replace(strContent,"<marquee width=90% behavior=alternate scrollamount=3>$2</marquee>")
re.Pattern="(/[move/])(.+?)(/[//move/])"
strContent=re.Replace(strContent,"<MARQUEE scrollamount=3>$2</marquee>")
re.Pattern="/[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//GLOW]"
strContent=re.Replace(strContent,"<table width=$1 style=""filter:glow(color=$2, strength=$3)"">$4</table>")
re.Pattern="/[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//SHADOW]"
strContent=re.Replace(strContent,"<table width=$1 style=""filter:shadow(color=$2, strength=$3)"">$4</table>")
re.Pattern="(/[i/])(.+?)(/[//i/])"
strContent=re.Replace(strContent,"<i>$2</i>")
re.Pattern="(/[u/])(.+?)(/[//u/])"
strContent=re.Replace(strContent,"<u>$2</u>")
re.Pattern="(/[b/])(.+?)(/[//b/])"
strContent=re.Replace(strContent,"<b>$2</b>")
re.Pattern="(/[fly/])(.+?)(/[//fly/])"
strContent=re.Replace(strContent,"<marquee>$2</marquee>")
re.Pattern="(/[size=1/])(.+?)(/[//size/])"
strContent=re.Replace(strContent,"<font size=1 style=""line-height:"&amp;FontHeight&amp;"pt"">$2</font>")
re.Pattern="(/[size=2/])(.+?)(/[//size/])"
strContent=re.Replace(strContent,"<font size=2 style=""line-height:"&amp;FontHeight&amp;"pt"">$2</font>")
re.Pattern="(/[size=3/])(.+?)(/[//size/])"
strContent=re.Replace(strContent,"<font size=3 style=""line-height:"&amp;FontHeight&amp;"pt"">$2</font>")
re.Pattern="(/[size=4/])(.+?)(/[//size/])"
strContent=re.Replace(strContent,"<font size=4 style=""line-height:"&amp;FontHeight&amp;"pt"">$2</font>")
re.Pattern="(/[center/])(.+?)(/[//center/])"
strContent=re.Replace(strContent,"<center>$2</center>")
set re=Nothing
UBBCode=strContent
end function
Rem 过滤HTML代码
Public function HtmlAn(fString)
if not isnull(fString) then
fString = replace(fString, ">", "&amp;gt;")
fString = replace(fString, "<", "&amp;lt;")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), "&amp;nbsp;")
fString = Replace(fString, CHR(34), "&amp;quot;")
fString = Replace(fString, CHR(39), "&amp;#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) &amp;
CHR(10), "</font></P><P style=""font-size:"&amp;FontSize&amp;"pt;line-height:"&amp;FontHeight&amp;"pt"">")
fString = Replace(fString, CHR(10), "<BR> ")
HtmlAn = fString
end if
end function
End Class
</Script>
 
数据库转换好了,把连接改一下,对odbc进行一下修改就应该可以了。
 
DatabaseConnectionString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=data;User ID=sa;
Password=123 ;server=10.0.0.6"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open DatabaseConnectionString
这个地方肯定要改,改成连接asp的,至于下面的一些代码,也需要修改,但是得有针对性地改。
asp地连接代码:
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp;
Server.MapPath(db)
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" &amp;
Server.MapPath(db)
conn.Open connstr
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
685
import
I
I
回复
0
查看
759
import
I
后退
顶部