Username: Password:

怎样做一个高效的ASP数据库操作程式-ASP教程,数据库相关
来源:作者: 发布时间:2007-12-26 02:09:55







《%
dim conn,strconn
set conn = server.createobject("adodb.connection")
假如您的数据库的连接字符串和下面一句不符合,能够修改下句代码来适合您的数据库配置
strconn="driver={sql server};server=192.168.0.110;database=song1;uid=sa;pwd=sa;"
conn.open strconn
%》


《%
dim filename,postion
filename = request.servervariables("script_name")
postion = instrrev(filename,"/")+1
filename = mid(filename,postion)
%》


《%
function wawahtml(result)
if not isnull(result) then
result = server.htmlencode(result)
result = replace(result,vbcrlf,"
")
result = replace(result," "," ")
result = replace(result,chr(9),"    ") tab键
wawahtml=result
else
wawanhtml= "没有内容"
end if
end function
%》


《%
dim rs_wawa
set rs_wawa=server.createobject("adodb.recordset")
rs_wawa.open "p_song",conn,1,1,4
dim pages,allpages,page
pages=10
rs_wawa.pagesize=pages
allpages = rs_wawa.pagecount
page = clng(request("page"))
if isempty(page) or page<0 or page=0 then page=1
if page >rs_wawa.pagecount then page=rs_wawa.pagecount
if not(rs_wawa.bof and rs_wawa.eof) then
rs_wawa.absolutepage = page
end if
%》


《%
if request("action")="view" then
if request("id")<>"" then
dim id
id=clng(trim(request.querystring("id")))
set cm = server.createobject("adodb.command")
set cm.activeconnection = conn
cm.commandtext = "p_wawa_song"
cm.commandtype = 4
set p = cm.parameters
p.append cm.createparameter("@id",3,1,,id)
dim rs_song
set rs_song=server.createobject("adodb.recordset")
rs_song.open cm,,1,1
else
response.write("没有传递参数")
response.end()
end if
end if
%》


《%
if not isempty(request.form("submit")) then
call addnew
end if
sub addnew
on error resume next
song_author=request("song_author")
song_content=request("song_content")
song_name=request("song_name")
set cm = server.createobject("adodb.command")
set cm.activeconnection = conn
cm.commandtext = "insert_song"
cm.commandtype = 4
set p = cm.parameters
p.append cm.createparameter("@song_name",130,1,60,song_name)
p.append cm.createparameter("@song_content",202,1,4000,song_content)
p.append cm.createparameter("@song_author",130,1,20,song_author)
cm.execute
if err.number<>0 then
response.write err.description
else
response.write "ddd"
response.end
end if

set cm = nothing
response.redirect filename
end sub
%》








《%if request("action")="add" then%》






















添加歌词
歌曲作者:
歌曲名称:
歌曲内容:

《%end if%》



《%if request("action")="view" then%》















查看歌词
歌曲作者: 《%=rs_song("song_author")%》
歌曲名称: 《%=rs_song("song_name")%》
《%=wawahtml(cstr(rs_song("song_content")))%》

《%end if%》


《%if request("action")="hello" or request("action")="" then%》







欢迎使用蛙蛙歌词管理系统

残荷听雨,梨花飞雪,

落英缤纷时节。

晓来谁染枫林醉?点点都是离人泪.

活着,就是快乐!

自信,就是美丽!

有人爱,就是幸福。





《%end if%》




首页  添加歌曲

《%
if not(rs_wawa.bof and rs_wawa.eof) then
while not rs_wawa.eof and pages>0
%》



《%
rs_wawa.movenext
pages=pages-1
wend
rs_wawa.close:set rs_wawa=nothing
else
%》



《%=rs_wawa(1)%》
还没有添加歌曲呢

《%
end if
conn.close:set conn = nothing
%》
《%if page<>1 then%》
首页    上一页  
《%end if%》
《%if page<>allpages then %》
下一页   末页  
《% end if %》
当前第《%=page%》几页   共《%=allpages%》页



喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅