电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Asp>>VB开发ASP组件经典事例[一]:

VB开发ASP组件经典事例[一]

来源:www.cncfan.com | 2006-11-3 | (有2243人读过)

[一] 纯ASP脚本表现功能[增/删/查/改]

Test_Tb.asp
----------------------------------------------------------------------------------------------------------

<script language="javascript">

function operate(obj)

{ window.location.href='operate.asp?action='+obj.value+'&cd_id='+f1.cd_id.value+'&cd_name='+f1.cd_name.value+'&cd_author='+f1.cd_author.value;

}

</script>

<html>

<body>

Temp_CD Table

<form name="f1">

<ul>

<li>cd_id:<input type="text" name="cd_id" />

<li>cd_name:<input type="text" name="cd_name" />

<li>cd_author:<input type="text" name="cd_author" />

</ul>

<input type="button" value="Add" onClick="operate(this)" />

<input type="button" value="Delete" onClick="operate(this)" />

<input type="button" value="Search" onClick="operate(this)" />

<input type="button" value="Update" onClick="operate(this)" />

</form>

</body>

</html>

operate.asp
----------------------------------------------------------------------------------------------------------

<%

Option Explicit

Response.Buffer = True

On Error Resume Next

Dim StrConn,Conn,RS,Sql

Dim action,cd_id,cd_name,cd_author

Dim Msg



StrConn = "driver={sql server};server=(local);uid=sa;password=love!@#;database=Northwind"

Set Conn = Server.CreateObject("ADODB.Connection")



action = Request.QueryString("action")

cd_id = Request.QueryString("cd_id")

cd_name = Request.QueryString("cd_name")

cd_author = Request.QueryString("cd_author")



Response.Write("action:"&action&"<br>")

Response.Write("CD_ID:"&cd_id&"<br>")

Response.Write("CD_Name:"&cd_name&"<br>")

Response.Write("CD_Author:"&cd_author&"<p>")



Conn.Open StrConn

If Err.Number <> 0 Then

Msg = "The Database Connect Fail !"

Else

If action = "Search" Then

Sql = "Select * From Temp_CD Where CD_ID = "&cd_id

Set Rs = Conn.execute(Sql)

If Err.Number <> 0 Then

Msg = action&" Fail!"

Else

If Rs.Eof Then

Msg = "No Any Records!"

Else

Msg = "CD_Name:"&Rs("CD_Name")&"<br>CD_Author:"&Rs("CD_Author")

End If

End If

Rs.Close

Set Rs = Nothing

Else

Select Case action

Case "Add"

Sql = "Insert Temp_CD (CD_Name,CD_Author)values('"&cd_name&"','"&cd_author&"')"

Case "Delete"

Sql = "Delete Temp_CD Where CD_ID = "&cd_id

Case "Update"

Sql = "Update Temp_CD Set CD_Name = '"&cd_name&"',CD_Author = '"&cd_author&"'"

End Select

Conn.execute(Sql)

If Err.Number <> 0 Then

Msg = action&" Fail!"

Else

Msg = action&" Success!"

End If

End If

Conn.Close

Set Conn = Nothing

End If

Response.Write(Msg)

%>


附:
----------------------------------------------------------------------------------------------------------

不知代码是否可以更精练?


Asp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号