asp操作数据库以及文本文件

asp操作sql

显示表的内容
<%
set conn=Server.Createobject("adodb.connection") 
connstr="driver={SQL Server};server=WIN-I1F2TODGAHT;uid=wg365;pwd=mark168@;database=WebBuy" 
on error resume next
conn.open connstr 
response.write conn.state 
if err then 
response.write "错误!"
else
response.write "成功!"
sql = "select * from Admin"  
set rs= Server.CreateObject("ADODB.RecordSet")  
rs.Open sql,conn,1,1  
'获得连接信息与查询结果行数  
Response.write("连接1:"&conn.ConnectionString&"
spt_values行数:"
&rs.recordcount&"

"
) '循环结果输出 do While not rs.eof Response.write(rs(0)&","&rs(1)&","&rs(2)&","&rs(3)&","&rs(4)&"
"
) rs.MoveNext Loop rs.close() conn.close() end if err.clear %>
插入数据到表 alert是提示框,confirm是询问框 <% set conn=Server.Createobject("adodb.connection") connstr="driver={SQL Server};server=WIN-I1F2TODGAHT;uid=wg365;pwd=mark168@;database=WebBuy" on error resume next conn.open connstr if err then response.write "错误!" else m=request("m") sql="INSERT INTO Admin (Accounts,Pwd) VALUES ('Wilson','"&m&"')" set rs= Server.CreateObject("ADODB.RecordSet") rs.Open sql,conn,1,1 rs.close() conn.close() Response.Write("") Response.Write("") end if err.clear %> DELETE FROM 表名 WHERE 条件 update good set gicd=6 where gicd=4

asp操作txt




读取txt
<%
dim fso,f
    set fso=server.CreateObject("Scripting.FileSystemObject")
    Set f =  fso.OpenTextFile(Server.MapPath("1.txt"),1) 
    Do  While  Not  f.AtEndOfStream   
    response.write f.readline
    loop
    f.close
    set f=nothing
    set fso=nothing
%>


line=txt.ReadAll'读取文件中的所有数据 
line=txt.ReadLine'从文件中读取一行数据
line=txt.Read(N)'从文件中读取N个字节的数据
txt.SkipLine跳过一行


写入txt
<%

testfile=server.mappath("1.txt")

msg=request("df")

set fs=server.createobject("scripting.filesystemobject")

set thisfile=fs.opentextfile(testfile,8,true,0)

thisfile.writeline("message="+df) 

thisfile=close

set fs=nothing

%>



<%
dim fso,f
    set fso=server.CreateObject("Scripting.FileSystemObject")
    Set f =  fso.OpenTextFile(Server.MapPath("1.txt"),1) 
    f.SkipLine
    one=f.readline
    response.write one   
    f.close
    set f=nothing
    set fso=nothing
%>

注意事项


1、iis管理器->电脑主页-》iis-》asp-》调试属性-》将错误发送到浏览器-》true-》应用
2、iis管理器-》电脑主页-》iis-》错误页-》编辑功能设置-》详细错误-》确定

2、win64位操作系统会报错,iis管理器-》应用程序池-》设置应用程序池默认设置-》启用32位应用程序-》true-》确定

你可能感兴趣的:(asp操作数据库以及文本文件)