
set conn=Server.CreateObject("ADODB.Connection")
conn.open "provider=sqloledb.1Persist Security Info=falsedata source=数据库地址User ID=用户名pwd=用户密码Initial Catalog=数据库名字"
'定义表
Set ds=Server.CreateObject("ADODB.Recordset")
'查询语句
sql="select * from Table1"
'查询
ds.open sql,conn,1,1
'循环绑定
Do While Not ds.Eof
Response.Write "<li><span>"&ds("date")&"</span><span>"&ds("id")&"</span></li>"
ds.Movenext
Loop
'关闭对象
ds.CLose
Set ds=Nothing
conn.CLose
Set conn=Nothing
'第一处,请注意橙色语法部分sql="select * from zhang"rs.open sql,conn,1,1
If Not (rs.bof And rs.eof) Then '不为空时显示
do while not rs.eof%>'<%= rs("hao") %>',<% rs.movenext
loop
Else
response.write "没有数据"
End If
rs.close
'第二处,请注意橙色语法部分
sql="select * from zhangdan where hao='"&request("danhao")&"'"
rs.open sql,conn,1,3
If Not(rs.bof And rs.eof) Then '不为空时,表示有数据才能更新
if request("act")="mod" then
rs.update
End If
rs.close
<%set conn=server.createobject("adodb.connection") '建立一个ADO连接conn.open "driver={microsoft access driver (*.mdb)}dbq="&server.mappath("liuyan.mdb") 打开数据库liuyan.mdb
name=request.form("name") 获取表单中得到的name值。
message=request.form("message")接收参数,获取表单中的message值
exec="insert into liuyan(name,message)values('"+name+"','"+message+"')" 把name message插入数据库的SQL代码。
conn.execute (exec)执行上述SQL语句
conn.close 关闭数据库连接
set conn=nothing 清除对象
response.write "记录添加成功!" 在网页上打出"记录添加成功"
%>
---------------------------------------
exec是一个自定义的变量。你可以用自己喜欢的名称来定义。不过一般不用容易冲突的或者纯数字。
括号那是SQL规范。具体为什么要加,那等你明白了SQL后就知道了。
+是连接符,可能你用的是Javascript语言。这里是把前后连接起来。VB中我们一般用&连接。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)