txt文件是下面这样的,
一行一条数据,用逗号分隔
下面写出asp文件
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--#include file="inc/conn.asp" -->
<%
filespec=server.mappath("txt.txt")
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
i=0
Do While theFile.AtEndOfStream <> True
session("line"&i) = theFile.ReadLine
i=i+1
Loop
theFile.Close
ReadEntireFile = retstring
for j=0 to i-1
arry=split(session("line"&j),",")
'arry(0),arry(1),arry(2)
'分别为:张三 男 30岁
'然后进行数据存储
set rs3=server.createobject("adodb.recordset")
sql="select * from keywords"
rs3.open sql,conn,3,3
rs3.addnew
rs3("text")=arry(0)
rs3("url")=arry(1)
rs3.update
response.write session("line"&j)+"<br>"
next
%>
原文地址:http://www. ......
发一个标准的数据库连接代码。希望对大家有帮助。
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
'更改数据库名字
db="data/dvBBS5.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%> ......
在提交页面中验证session("GetCode")
<%@CodePage="65001"%>
<%
Call Com_CreatValidCode("GetCode")
Sub Com_CreatValidCode(pSN)
' 禁止缓存
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
'Response.ContentType = "Image/BMP"
Randomize
Dim i, ii, iii
Const cOdds = 4 ' 杂点出现的机率
Const cAmount = 13 ' 文字数量
Const cCode = "0123456789+=?"
' 颜色的数据(字符,背景)
Dim vColorData(1),vColorRandom(10)
'vColorData(0) = ChrB(Int(Rnd*155)+100) & ChrB(Int(Rnd*155)+100) & ChrB(Int(Rnd*155)+100) ' 蓝0,绿0,红0(黑色)
vColorRandom(0)=ChrB(150) & ChrB(0) & ChrB(0)
vColorRandom(1)=ChrB(0) & C ......
1、直接将页面内容存在变量中后输出:
StringBuilder IndexContentResult= new StringBuilder(); //存放输出页面的HTML
IndexContentResult.Append("<html>\n");
IndexContentResult.Append(" <head>\n");
IndexContentResult.Append(" <title>title</title> \n");
IndexContentResult.Append(" </head>\n");
IndexContentResult.Append(" <body>\n");
...
IndexContentResult.Append(" <body>\n");
IndexContentResult.Append("</html>\n");
string tempfile = Server.MapPath("~");
tempfile = tempfile + "index.htm";
System.IO.StreamWriter sr = new System.IO.StreamWriter(tempfile, false, System.Text.Encoding.Default);
sr.Write(IndexContentResult.ToString());
sr.Close() ......
/* from: http://www.techmango.com/blog/article/DotNet/Explore_Asp_net_postback_mechanism.htm */
__doPostBack作为在asp.net中一个很核心很重要的部分,我们有必要深入了解一下.
其实,__doPostBack是一个很简单的脚本函数.代码如下:
//__doPostBack<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />function __doPostBack(eventTarget, eventArgument) {if (!theForm.onsubmit || (theForm.onsubmit() != false)) {theForm.__EVENTTARGET.value = eventTarget;theForm.__EVENTARGUMENT.value = eventArgument;theForm.submit();}}
原来是在submit上做文章啊.microsoft呈现给我们的就是这种精巧的思维!
我看到,asp.net现在页面上添加了两个hidden input,这两个input分别用来存放触发postback的control的ID和参数.这就是我们大部分人认识到的:
__doPostBack(obj1,obj2)的第一个参数是控件ID,第二个参数是postback的参数.然后就可以在后台用Request.Form["__EVENTTARGET"]和 Request.Form["__EVENTARGUMENT"]取得控件ID和参数.
不过,另外要 ......
效果图
Default.aspx页面的内容
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Verify._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="viewImg.aspx" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div> ......