ASP 编程中 20 经典例子
- 格式:docx
- 大小:26.57 KB
- 文档页数:9
常用ASP代码大全1.获得系统时间:<%=now()%>2. 取得来访用的IP:<%=request.serverVariables("remote_host")%>3.获得系统,浏览器版本:<script>window.document.write(" 版本:"+navigator.appName+navigator.appVersion+" browser.")</script>4.去除IE混动条:<body scroll="no"><body style="overflow-y:hidden">5.进入网站,跳出广告:<script language="javascript"><!--<!-- 注意更改文件所在路径-->window.open(''",'''',''height=200,width=300,top=0,left=30'');// --></script>6.随机数:<%randomize%><%=(int(rnd()*n)+1)%>N 为可改变数7.向上混动代码:<marquee direction="up" scrolldelay="200" style="font-size: 9pt; color: #FF0000;line-height: 150%; font-style:italic; font-weight:bold" scrollamount="2" width="206"height="207" bgcolor="#FFFF00">Unix中文站</marquee>8.自动关闭网页:<script LANGUAGE="javascript"><!--setTimeout(''window.close();'', 10000); //60秒后关闭// --> </script><p align="center">本页10秒后自动关闭,请注意刷新页面</p>9.随机背景音乐:<%randomize%><bgsoundsrc="/qz.q/mids/<%=(int(rnd()*60)+1)%>.mid"loop="-1"> 可以修改数字,限制调用个数,我这里是60个.10.自动刷新本页面:<script><!--var limit="0:10"if (document.images){var parselimit=limit.split(":")parselimit=parselimit[0]*60+parselimit[1]*1 }function beginrefresh(){if (!document.images)returnif (parselimit==1)window.location.reload()else{parselimit-=1curmin=Math.floor(parselimit/60)cursec=parselimit%60if (curmin!=0)curtime=curmin+"分"+cursec+"秒后重刷本页!"elsecurtime=cursec+" 秒后重刷本页!"window.status=curtimesetTimeout("beginrefresh()",1000) } }window.onload=beginrefreshfile://--></script>11.ACCESS数据库连接:<%option explicitdim startime,endtime,conn,connstr,dbstartime=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 connstrfunction CloseDatabaseConn.closeSet conn = NothingEnd Function %>12.SQL数据库连接:<%option explicitdim startime,endtime,conn,connstr,dbstartime=timer()connstr="driver={SQLServer};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs"Set conn = Server.CreateObject("ADODB.Connection")conn.Open connstrfunction CloseDatabaseConn.closeSet conn = NothingEnd Function%>13.用键盘打开网页代码:<script language="javascript">function ctlent(eventobject){ if((event.ctrlKey && window.event.keyCode==13)(event.altKey && window.event.keyCode==83)){ window.open('网址','','') } }</script>这里是Ctrl+Enter和Alt+S的代码自己查下键盘的ASCII码再换就行14.让层不被控件复盖代码:<div z-Index:2><object ***></object></div> #前面<div z-Index:1><object ***></object></div> #后面<div style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div><div style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>。
目录1、创建 ASP 网页 (2)2、使用脚本语言 (8)3、使用变量和常量 (11)4、与客户端脚本交互操作 (16)5、编写过程 (19)6、使用集合 (22)7、处理用户输入 (29)8、使用组件和对象 (37)9、设置对象作用域 (41)10、将内容发送到浏览器 (45)11、包含文件 (52)12、管理会话 (54)13、访问数据源 (62)14、理解事务 (77)15、调试 ASP 脚本 (82)16、内置 ASP 对象 (86)创建 ASP 网页Active Server Pages (ASP) 文件是带有 .asp 扩展名的文本文件,它由下列内容组合而成:∙文本∙HTML 标记∙服务器端脚本使用 .asp 扩展名重命名现有的 .htm 或 .html 文件可以快速创建 .asp 文件。
如果文件不包含任何 ASP 功能,则服务器不进行 ASP 脚本处理,并很快将文件发送到客户端。
这为 Web 开发人员提供了极大的灵活性,因为即使目前不希望在文件中添加 ASP 功能,也可以使用 .asp 作为扩展名。
要在 Web 上发布 .asp 文件,请将新文件保存到网站上的虚拟目录(确保目录启用了“脚本”或“执行”权限)。
然后,使用浏览器输入文件的 URL 来请求文件。
(请注意,必须处理 ASP 网页,因此您无法通过输入其物理路径请求 .asp 文件)。
在浏览器中加载文件之后,可以发现服务器返回了 HTML 页。
这看起来有些奇怪,但要记住在发送文件之前,服务器将解析并执行所有 ASP 服务器端脚本。
用户将始终接收到标准的 HTML。
可以使用任意文本编辑器创建 .asp 文件。
随着对编辑器的深入使用,您将发现使用具有更多 ASP 支持的编辑器(如 Microsoft Visual InterDev 等)效率更高。
详细信息,请访问Microsoft Visual InterDev 网站。
添加服务器端脚本命令服务器端脚本是一系列指令,用于向 Web 服务器连续发出命令。
ASP十大常用代码第一节:注册系统注册几乎是每个网站都要使用的,去论坛要注册,聊天要注册,几乎无处不注册,所以注册是所有ASP应用程序中最常见的。
第二节:留言薄互联网最大的特点是互动性,让网友在留言薄上留下自己的意见能使网站的人气值上升不少。
第三节:调查系统利用网络进行一些调查是非常常见的,轻轻一点投下自己一票,因此有一个调查系统能为网站增色不少。
第四节:购物车购物车这个名字取自超级市场的购物推车,不过这个小小的推车却是每个购物网站必备的。
第五节:计数器在浏览网页的时侯,常常可以看见一些“当前网站上的人数是xxxx人”的在线人数统计。
第六节:论坛系统论坛可以说是网站中最受网友欢迎的地方,网友可以在这里自由的发表自己的意见,网站人气的高低很大程度上由论坛决定,因此为我们的网站增加一个论坛是必须的。
第七节:聊天室当你独自在Internet上浏览时,你并不是一个孤单的“旅人”,因为每时每刻总有成千上万的人同时在网上浏览,你可以同他们聊聊天,交谈几句,让自己体验一下“网”内存知己、天涯若比邻的感觉第八节:EMail 当你独自在Internet上浏览时,你并不是一个孤单的“旅人”,因为每时每刻总有成千上万的人同时在网上浏览,你可以同他们聊聊天,交谈几句,让自己体验一下“网”内存知己、天涯若比邻的感觉。
第九节:搜索系统一个大型网站内容众多,来访者往往很难找到自己所需要的东西,这时候就需要一个站内搜索来帮助来访者更快的找到索要的资料,所以搜索系统是一个大型网站必备系统。
第十节:分页程序从程序上说分页只是一种小技巧,但确实却是一个非常重要的小技巧,好,少说废话,我们开始吧。
好了以上是我要给大家分别讲解的教程.欢迎大家及时收藏和支持这里先给大家讲解第一节:注册系统(一),设定注册页面的外观:在这个例子中涉及了五个页面,其中有三幅是一般的htm文件,另外的两幅是asp文件,在这里制作利用的工具是frontpage98,但是大部分的asp代码还是要自己输入的:1,设定原来已经注册的用户进入的外观:在这里设置了两个文本框,一个超级链接和两个按钮。
ASP中常用代码Cookie的用法://Cookie的用法HttpCookie cookie = new HttpCookie("first"); //第一个Cookie cookie.Expires = DateTime.Now.AddDays(30); //设置Cookie的消失时间,时间为30天cookie.Values["name"] = "lsc"; //设置Cookie的值//name <-->lsc为键值对cookie.Values["password"] = "12345";Response.Cookies.Add(cookie); //将指定的Cookie保存到本机//获取Cookie的值HttpCookie c = (HttpCookie)Request.Cookies["first"];Response.Write(c.Values["name"] + "<br/>");Response.Write(c.Values["password"]);Application 的用法:写在Gloal.asaxvoidApplication_Start(object sender, EventArgs e){// Code that runs on application startup//服务器启动时运行的代码//关于计数器的使用//在此初始化计数器Application["count"] = 0; //当服务器启动时调用,该网站访问数为0开始}写在页面端protected void Page_Load(object sender, EventArgs e) {try{//取出application中的值|Application.Lock();int count = (int)Application["count"];count++;Application["count"] = count; //将此返回服务?器Response.Write("你是第+Application["count"] + "位访客¨a");Application.UnLock();}catch (Exception ex){Response.Write(“<script>alert(“+ex.Message+”)</script>”); }}如果写在页面端,则用户刷新一次,访问人数就增加voidSession_Start(object sender, EventArgs e){// Code that runs when a new session is started//在新会话启动时运行的代码//取出application中的值Application.Lock();int count = (int)Application["count"];count++;Application["count"] = count; //将此返回服务器Response.Write("你是第" + Application["count"] + "位访客");Application.UnLock();}将此写在Global.asax中使得页面只有通过重新访问,访问数才能增加,否则不能增加Lock()和UnLock()的意义是必须是一个加完后,另外一个在加Response的用法:Response用于向页面输出内容和实现页面的重定向Response.Write();Resposne.Redirect("网址")Response.Cookies.Add(); 用于添加CookieRequest的用法:Request用于获取表单的值String name=request.queryString["name"];String name=request.from["name"];String name=request.params["name"]; --最常用的一种方法String name=request["name"];Session的用法:(Session中可以传递各种数据类型的数据也可以传递类)Session用于在各个页面之间传递数据首先是将值存放在Session中:Session["name"] = name;Session["password"] = password;然后获取值:string name = (string)Session["name"];string password = (string)Session["password"];###在实际工作中,Session传递的值一般是一个封装类JavaScript中页面自动跳转的方法:将其添加在中即可实现中的自动跳转<SCRIPT LANGUAGE="JavaScript"><!--function redirect() { //跳转页window.location = "Default.aspx";}timer = setTimeout('redirect()', 5 * 1000); //跳转//--></SCRIPT>在中设置密码框即在TextBox中添加TextMode="password" ---利用中自身的TextBox设置密码框添加TextMode属性关于DropDownList的数据绑定:首先在DropDownList中的事件SelectedIndexChanged中添加:this.Image1.ImageUrl = "img/" + this.DropDownList1.SelectedValue.ToString();1、利用图形界面进行数据绑定,详见数据绑定视频2、利用ArrayList容器进行数据绑定,但是只能是5条一下的数据if (!IsPostBack){ArrayList list = new ArrayList();list.Add("1.jpg");list.Add("2.jpg");list.Add("3.jpg");this.DropDownList1.DataSource = list; //指定数据源this.DropDownList1.DataBind();}3、利用数据库操作进行动态的数据绑定(较为正规的用法)//利用数据库操作进行动态数据绑定if (!IsPostBack){stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=mldn;Uid=china;Pwd=1 2345678";SqlConnectionsqlConn = new SqlConnection(strConn);sqlConn.Open();SqlCommandcmd = new SqlCommand();mandText = "select * from Images";cmd.Connection =sqlConn;SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);this.DropDownList1.DataSource = dt;this.DropDownList1.DataTextField = "imgs"; //添加显示给用户的数据this.DropDownList1.DataValueField = "imgs"; //添加传递给服务器的数据this.DropDownList1.DataBind();}在中利用onClientClick()事件调用JavaScript代码而不用onClick()事件在代码后面添加return false 阻止后面的代码执行在判断姓名文本框、密码框等不能为空的判断时,避免没有添加页面仍然跳转则在每一个判断后面添加一上return false,同时在onClientClick()中添加return javaScript方法CheckBoxList的用法:int count = this.CheckBoxList1.Items.Count;for (int index = 0; index <= count; index++){if (this.CheckBoxList1.Items[index].Selected){Response.Write(this.CheckBoxList1.Items[index].Text);}}RadioButtonList的用法:for (int index = 0; index < this.RadioButtonList1.Items.Count; index++){if (this.RadioButtonList1.Items[index].Selected){Response.Write(this.RadioButtonList1.Items[index].Text);}}Data中的Repeater的用法:主要用于分页首先拖动一个Reoeater控件,然后配置数据源在切换到代码视图,添加相应的模板,其中()模板如下:<HeaderTemplate></HeaderTemplate><ItemTemplate></ItemTemplate> --必写<FooterTemplate></FooterTemplate><AlternatingTemplate></AlternatingTeplate> --隔行显示模板,实现隔行的显示方式对应实例:<form id="form1" runat="server"><div><asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"><HeaderTemplate><table border="1"><tr><td width="100">图片</td><td width="100">值</td></tr></table></HeaderTemplate><ItemTemplate><table border="1"><tr style=" color:Green"><td width="100"><%# Eval("imgs") %></td><td width="100"><%# Eval("imgsValue")%></td></tr></table></ItemTemplate><AlternatingItemTemplate><table border="1"><tr style=" color:Red"><td width="100"><%# Eval("imgs") %></td><td width="100"><%# Eval("imgsValue") %></td></tr></table></AlternatingItemTemplate><FooterTemplate><table border="1"><tr><td colspan="2">这是一个测试程序!!</td></tr></table></FooterTemplate></asp:Repeater><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mldnConnectionString %>" SelectCommand="SELECT * FROM [Images]"></asp:SqlDataSource><br /><br /><br /><br /></div></form>ASP中的分页:真分页和假分页假分页:using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;public partial class page : System.Web.UI.Page{privateintpageNumber = 0;privateintlineCount;public void pages(){stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select * from fangyuan";SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);PagedDataSourcepds = new PagedDataSource();pds.DataSource = dt.DefaultView;pds.AllowPaging = true; //是否允许分页pds.PageSize = 2; //指定每页显示多少条数据pds.CurrentPageIndex = pageNumber; //指定显示的页码,用该变量控制翻页this.Repeater1.DataSource = pds;this.Repeater1.DataBind();conn.Close();}protected void Page_Load(object sender, EventArgs e){this.pages();stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select count(*) from fangyuan";object o = cmd.ExecuteScalar();lineCount = Convert.ToInt32(o);}protected void LinkButton1_Click(object sender, EventArgs e){try{pageNumber = 0;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton2_Click(object sender, EventArgs e){try{if (pageNumber< 0){Response.Write("不能再向上翻页了!");}else{pageNumber -= 1;this.pages();}}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton3_Click(object sender, EventArgs e) {try{pageNumber = 0;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton4_Click(object sender, EventArgs e) {try{pageNumber = 1;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton5_Click(object sender, EventArgs e) {try{pageNumber = 2;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton7_Click(object sender, EventArgs e) {try{if (pageNumber == (lineCount - 1)){Response.Write("不能再向下翻页了!");}else{pageNumber += 1;this.pages();}}catch (Exception ex){Response.Write(ex.Message);}}protected void LinkButton8_Click(object sender, EventArgs e) {try{pageNumber = lineCount - 1;this.pages();}catch (Exception ex){Response.Write(ex.Message);}}}DataList的用法:(绑定数据的方式与Repeater相同)与Repeater相比较,DataList的功能更强大,可以实现删除,具体用法如下:DataList绑定数据的两种方式:1、利用图形化界面对数据进行绑定2、动态的对数据进行绑定stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "select * from fangyuan";SqlDataAdaptersda = new SqlDataAdapter(cmd);DataTabledt = new DataTable();sda.Fill(dt);this.DataList1.DataSource = dt;this.DataList1.DataKeyField = "bianhao"; //指定以何种字段为标准 ---关键this.DataList1.DataBind();conn.Close();删除方法:string bianhao = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); //用于获取对应的编号 ----关键stringstrConn ="server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;Uid=china";SqlConnection conn = new SqlConnection(strConn);conn.Open();SqlCommandcmd = new SqlCommand();cmd.Connection = conn;mandText = "delete from fangyuan where bianhao='" + bianhao + "'";cmd.ExecuteNonQuery();conn.Close();每删除一次后对数据进行重新绑定,实现更新DXControls外部控件的使用:在使用DXControls时注册代码(放在<% @page 的下面)<%@ Register Assembly="DXControls" Namespace="DXControls" TagPrefix="cc1" %>在复制<cc1:dxtb id="concentdx" runat="server" height="100px" width="450px"></cc1:dxtb>该段代码到.aspx文件中在使用该控件时,必须在工程中导入Bin文件夹,同时该文件夹中必须存在DXControls.dll文件,还应导入dxtb文件夹,里面包含有相应的文件中验证控件的使用1、RequiredFieldValidator必填项验证,如网络上的*为必填项的实现必须对两个属性进行更改:ControlToValidate指定对哪个控件进行验证ErrorMessage当输入错误时显示的错误信息2、RegularExpressionValidator正则表达式验证,如对密码、邮箱等的验证必须对三个属性进行更改:ControlToValidate指定对哪个控件进行验证ErrorMessage当输入错误时显示的错误信息ValidationExpression写出对应的正则表达式3、RangeValidator数字界限验证,如3-100常见的正则表达式的匹配字符串:\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 为匹配邮箱地址防止用户未登录就访问页面的代码:<%If(Session(“name”) == null){Response.Redirect(“Login.aspx”);}%>通过Seesion在用户登录时存值,再每一个页面都判断是否存在Session传递的值,已判断用户是否登录,通常传递类Linq的使用:查询操作://读取配置文件tStudentDataClassesDataContext context =new StudentDataClassesDataContext();//取出数据表中的所有内容System.Data.Linq.Table<student> list = context.GetTable<student>();//按照需求查询var query = from student in list select student;//或者语句的使用var query = from Person in context.Persons where Person.id == 1 || =="lsc" select Person;foreach(var student in query){Response.Write(+"<br />");}删除操作:(先查找再删除)PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();var delete = from Person in context.Persons where Person.id==1 select Person; foreach (var Person in delete){//删除操作context.Persons.DeleteOnSubmit(Person);}context.SubmitChanges(); //提交操作Response.Write("删除成功");添加数据操作:PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();Person p = new Person();p.id = 1; = "flq";p.password = "flq";context.Persons.InsertOnSubmit(p);//添加数据context.SubmitChanges(); //提交操作修改数据操作:PersonDataClassesDataContext context =new PersonDataClassesDataContext();System.Data.Linq.Table<Person> list = context.GetTable<Person>();var update = from Person in context.Persons where Person.id==4 select Person; foreach (var P in update){ = "wms";P.password = "wms";}context.SubmitChanges();利用Linq遍历数组:利用Linq对容器进行操作:如何利用Linq进行降序排列:以“c”结尾长度不大于5的人名。
asp 案例ASP案例。
ASP是一种基于服务器的脚本语言,用于创建动态交互式网页。
它可以与HTML一起使用,也可以与其他服务器端脚本语言一起使用。
ASP允许开发人员使用VBScript、JScript等脚本语言编写网页。
下面我们将通过几个实际案例来展示ASP的应用。
案例一,用户登录验证。
假设我们有一个网站,需要用户登录后才能访问某些页面。
我们可以使用ASP来实现用户登录验证功能。
首先,我们需要创建一个登录页面,其中包括用户名和密码的输入框,以及登录按钮。
然后,我们编写一个ASP脚本,当用户点击登录按钮时,脚本将获取用户输入的用户名和密码,然后与数据库中存储的用户信息进行比对。
如果用户名和密码匹配成功,就允许用户访问受保护的页面;否则,提示用户输入错误。
案例二,数据查询与展示。
假设我们有一个产品列表页面,需要从数据库中获取产品信息并展示在网页上。
我们可以使用ASP来实现数据查询与展示功能。
首先,我们需要编写一个ASP脚本,连接到数据库,并编写SQL查询语句来获取产品信息。
然后,将查询结果展示在网页上,可以使用HTML表格来展示产品名称、价格等信息。
通过ASP脚本,我们可以实现动态获取数据库中的数据,并将其展示在网页上,实现了页面内容的动态生成。
案例三,在线留言板。
假设我们需要在网站上添加一个在线留言板,让用户可以发表留言并展示在网页上。
我们可以使用ASP来实现在线留言板功能。
首先,我们需要创建一个留言页面,包括留言标题、内容输入框,以及提交按钮。
然后,编写一个ASP脚本,当用户点击提交按钮时,将用户输入的留言内容保存到数据库中。
另外,我们还可以编写另一个ASP脚本,用于从数据库中获取留言信息,并展示在网页上。
通过ASP脚本,我们可以实现用户留言的提交和展示功能,实现了网站与用户的互动。
结语。
通过以上几个案例,我们可以看到ASP在动态网页开发中的重要作用。
它可以实现用户登录验证、数据查询与展示、在线留言板等功能,为网站的交互性和动态性提供了强大的支持。
/download/info /1701.htm/Program/Asp/112 TM562008.html<%dim ConnStringset conn=server.CreateObject("adodb.connection")ConnString="provider=microsoft.jet.oledb.4.0;data source=" & server.MapPath("#kucun.mdb") conn.open ConnString'连接数据库%>2000下使用asp访问数据库时,在conn.open始终发生8007007f错误,重装IIS和access均得不到解决。
我在网上查到的解决办法是将oledb32.dll 解压到以下两个目录,然后重启服务器:1) C:\WINNT\system32\dllCache2) C:\Program Files\Common Files\System\OLE DB<%dim conn,exec,rsset conn=server.createobject("adodb.connetion")conn.open "driver={microsoft access driver(*.mdb)};dbq="&server.mappath("show.mdb")exec="select * from list"set rs=server.createobject("adodb.recordset")rs.open,exec,conn,1,1%>ASP中连接数据库的错误解决新解决办法Provider 错误80004005 未指定的错误的新解决办法.这两天运行的好好的点击统计程序突然出错了,显示的就是:------------------------------------------Provider 错误80004005未指定的错误------------------------------------------在网上找了一大圈,发现大家提供的办法我都试过了,没有一个有作用的.方法有以下:1.开始运行regsvr32 jscript.dll (命令功能:修复Java动态链接库)开始运行regsvr32 vbscript.dll(命令功能:修复VB动态链接库)开始运行iisreset (命令功能:重启IIS)开始运行msjetoledb40.dll2.给系统临时文件夹%windir%/temp/ 加上IUSR_COMPUTER 用户的读写权限3.ASP连接Access数据库的时候,如果频繁刷新页面,出现80004005 未指定错误,数据库不能连接,但是过大约10多分钟后再刷新就可以连接。
1.计算机usingSystem.Windows.Forms;namespace WindowsFormsApplication2{public partial class Form1 : Form{public Form1(){InitializeComponent();}private string firstNo = "";private string op = "";private void input_Click(object sender, EventArgs e){Button btn = sender as Button;this.textBox1.Text = this.textBox1.Text + btn.Text;}private void computer_Click(object sender, EventArgs e){Button btn = sender as Button;if (btn.Text != "="){if (this.textBox1.Text == "")MessageBox.Show("请输入运算数据:");else{firstNo = this.textBox1.Text;op = btn.Text;this.textBox1.Text = "";}}if (btn.Text == "="){if (op== ""||this.textBox1.Text=="")MessageBox.Show("请合理进行操作:");else{stringsecondNo = this.textBox1.Text;double result;switch (op){case"+":result = Convert.ToInt32(firstNo) + Convert.ToInt32(secondNo);this.textBox1.Text =result.ToString();break;case"-":result = Convert.ToInt32(firstNo) - Convert.ToInt32(secondNo);this.textBox1.Text = result.ToString();break;case"*":result = Convert.ToInt32(firstNo) * Convert.ToInt32(secondNo);this.textBox1.Text = result.ToString();break;case"/":result = Convert.ToInt32(firstNo) / Convert.ToInt32(secondNo);this.textBox1.Text = result.ToString();break;} } }}private void textBox1_TextChanged(object sender, EventArgs e){}}}2窗口触发,在form2中输入字符,在form1中显示Form 1:usingSystem.Windows.Forms;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){Form2 f2=new Form2();If(f2.ShowDialog()==DialogResult.OK)//模式窗体,返回值为OK(确定){this.textBox1.Text=f2.getText();//form1中显示form2中的字符}}private void textBox1_TextChanged(object sender, EventArgs e){}}}Form2:usingSystem.Windows.Forms;namespace WindowsFormsApplication1{public partial class Form2 : Form{public Form2(){InitializeComponent();}public string getText(){return this.textBox1.Text;}}}ingSystem.Windows.Forms;namespace 学生信息注册{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e){}private void button1_Click(object sender, EventArgs e){bel13.Text =this.textBox1.Text; //label13.Text 显示textBox1.Text中的字符bel14.Text =this.textBox2.Text;//标签控件显示文本框的内容if (radioButton1.Checked)bel15.Text = "男";if (radioButton2.Checked)bel15.Text = "女"; //选择性别bel16.Text =this.dateTimePicker1.Text;//出生日期bel17.Text =boBox1.Text;//组合框系别string result = "";foreach (object item in this.listBox1.SelectedItems){//列表框允许选择多项result += item.ToString() + ";";}bel18.Text = result; //多项兴趣爱好}private void button3_Click(object sender, EventArgs e){//修改性别if (this.textBox3.Text == this.radioButton1.Text)this.radioButton1.Checked = true;if (this.textBox3.Text == this.radioButton2.Text)this.radioButton2.Checked = true;}private void button4_Click(object sender, EventArgs e){//修改出生日期this.dateTimePicker1.Value=Convert.ToDateTime(this.textBox3.Text);}private void button5_Click(object sender, EventArgs e){//修改系别boBox1.Text = this.textBox3.Text;}private void button2_Click(object sender, EventArgs e){//重置textBox1.Text = textBox2.Text = "";radioButton1.Checked =radioButton2.Checked=false;dateTimePicker1.ResetText();//出生日期comboBox1.SelectedIndex = -1;for (int i = 0; i < this.listBox1.Items.Count; i++){listBox1.SetSelected(i, false);}}private void button6_Click(object sender, EventArgs e){//回写this.textBox1.Text= bel13.Text;this.textBox2.Text= bel14.Text;if (bel15.Text == "男"){this.radioButton1.Checked = true;}if (bel15.Text == "女"){this.radioButton2.Checked = true;}this.dateTimePicker1.Text=bel16.Text;boBox1.Text = bel17.Text;string[] result = bel18.Text.Split(';');for (int i = 0; i < listBox1.Items.Count; i++){listBox1.SetSelected(i, false);}foreach (string item in result){for (int i = 0; i < listBox1.Items.Count; i++){if (item.Trim() == listBox1.Items[i].ToString())listBox1.SetSelected(i,true);}}} }}4.菜单与快捷菜单usingSystem.Windows.Forms;namespace 菜单{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){ }private void form2ToolStripMenuItem_Click(object sender, EventArgs e){Form2 form2 = new Form2();//创建子窗体实例form2.MdiParent = this;//为子窗体制定MID父窗体form2.Show();//显示子窗体}private void form3ToolStripMenuItem_Click(object sender, EventArgs e) {Form3 form3 = new Form3();form3.MdiParent = this;form3.Show();}private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e) {ColorDialogcdlg = new ColorDialog();cdlg.ShowDialog();}private void 字体ToolStripMenuItem_Click(object sender, EventArgs e) {FontDialogdlg = new FontDialog();dlg.ShowDialog();}private void form4ToolStripMenuItem_Click(object sender, EventArgs e) {Form4 form4 = new Form4();form4.MdiParent = this;form4.Show();}private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e) {this.Close();}private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { }private void form5ToolStripMenuItem_Click(object sender, EventArgs e){Form5 form5 = new Form5();form5.MdiParent = this;form5.Show();}private void 类视图ToolStripMenuItem_Click(object sender, EventArgs e){youtMdi(MdiLayout.TileHorizontal);}private void 属性窗口ToolStripMenuItem_Click(object sender, EventArgs e){youtMdi(MdiLayout.TileVertical);}private void 层叠ToolStripMenuItem_Click(object sender, EventArgs e){youtMdi(MdiLayout.Cascade);}}}Form4:usingSystem.Windows.Forms;namespace 菜单{public partial class Form4 : Form{public Form4(){InitializeComponent();}private void Form4_Load(object sender, EventArgs e){ }private void button1_Click(object sender, EventArgs e)//开始{int i;progressBar1.Value = 0;for (i = 0; i <= 100; i++){progressBar1.Value = i;//进程条trackBar1.Value = progressBar1.Value;//跟踪条label1.Text = i.ToString() + "/100";//0/100的变化}}private void trackBar1_Scroll(object sender, EventArgs e){progressBar1.Value = trackBar1.Value;label1.Text = progressBar1.Value.ToString() + "/100"; }private void label2_Click(object sender, EventArgs e){ }private void hScrollBar1_Scroll(object sender, ScrollEventArgs e){//水平滚动条label2.Text = hScrollBar1.Value.ToString();}}}Form5:usingSystem.Windows.Forms;namespace 菜单{public partial class Form5 : Form{public Form5(){InitializeComponent();}private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){if (comboBox1.SelectedIndex == 0)//列表视图listView1.View = rgeIcon;if (comboBox1.SelectedIndex == 1)listView1.View = System.Windows.Forms.View.SmallIcon;if (comboBox1.SelectedIndex == 2)listView1.View = System.Windows.Forms.View.Details;}}}5.数据库:Form1:usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace 数据库public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button5_Click(object sender, EventArgs e){if (conn != null){string msg = "服务器名称:" + conn.DataSource +"数据库名:"+conn.Database+";超时时间:" + conn.ConnectionTimeout + ";报文大小:" + conn.PacketSize + ";服务器版本:" +conn.ServerVersion;MessageBox.Show(msg);}}privateSqlConnection conn = null;private void button1_Click(object sender, EventArgs e){ //实例化变量conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456";}private void button2_Click(object sender, EventArgs e){if (conn !=null &&conn.State == ConnectionState.Closed)conn.Open();}private void button4_Click(object sender, EventArgs e){if (conn != null &&conn.State ==ConnectionState.Open)conn.Close();}private void button3_Click(object sender, EventArgs e){if (conn != null)MessageBox.Show(conn.State.ToString());}}}Form2:using System.Windows.Forms;usingSystem.Data.SqlClient;namespace WindowsFormsApplication1public partial class Form2 : Form{public Form2(){InitializeComponent();}privateSqlConnectioncomm = null;privateSqlConnection conn = null;private void Form2_Load(object sender, EventArgs e){conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; }private void button1_Click_1(object sender, EventArgs e){//查询//命令对象创建,并实例化好相关属性SqlCommand comm = new SqlCommand();comm.Connection = conn;mandText = "select * from 学生信息";mandType = CommandType.Text;conn.Open();SqlDataReader dr = comm.ExecuteReader();int i = 0;for (; dr.Read(); i++) ;MessageBox.Show(i.ToString());conn.Close();}private void button2_Click_1(object sender, EventArgs e){//修改SqlCommandcomm = new SqlCommand("update 学生信息set 性别='女' where 学号='200303020105'", conn);//mandText = "update 学生信息set 性别='女'where 学号=200303020116"; conn.Open();MessageBox.Show(comm.ExecuteNonQuery().ToString());conn.Close();}private void button3_Click(object sender, EventArgs e){//汇总SqlCommandcomm = conn.CreateCommand();mandText = "select count (*) from 学生信息";conn.Open();MessageBox.Show(comm.ExecuteScalar().ToString());conn.Close();}}}6.查看学生表和班级表SqlDataReader对象的使用usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace WindowsFormsApplication2{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;Persist Security Info=True;User ID=sa;Password=123456"; // 将数据库文件附加到SqlServer中conn.Open();SqlCommandcomm = conn.CreateCommand();mandText = "select * from 学生信息;select * from 班级";SqlDataReaderdr = comm.ExecuteReader();//列名要求通过sqlDataReader对象的方法获取int i = 0; //前10名学生的学号列、姓名列、身份证号列的值输出到控制台中while (dr.Read() && i < 10){string result = "";result += dr.GetName(0) + ":" + dr[0].ToString() + ";";result += dr.GetName(1) + ":" + (dr.IsDBNull(1) ? "" : dr["姓名"].ToString()) + ";";result += dr.GetName(3) + ":" + (dr.IsDBNull(3) ? "" :dr.GetString(3)) + ";";Console.WriteLine(result);i++; //字段值的获取尽量采用不同的方式获取}dr.NextResult();dr.Close();conn.Close();}}}7.数据查询筛选排序SqlDataAdapter+DataSet对象的使用usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace WindowsFormsApplication2{public partial class Form1 : Form{public Form1(){InitializeComponent();}DataSet ds = new DataSet();private void button1_Click(object sender, EventArgs e){StringconnStr="DataSource=.;InitialCatalog=JWInfo;UserID=sa;Password=123456";string sql = "select * from 学生信息";SqlDataAdapter ad = new SqlDataAdapter(sql, connStr);ad.Fill(ds,"学生信息");for(int i=0;i<ds.Tables[0].Rows.Count; i++){DataTabledt = ds.Tables [0];string temp ="学号:"+dt.Rows[i]["学号"].ToString()+";";temp +="姓名:"+dt.Rows[i][1].ToString()+";";temp += "身份证:" + dt.Rows[i]["身份证号"].ToString();//Console.WriteLine(temp);}//MessageBox.Show(ds.Tables[0].Rows.Count.ToString());输出学生表内学生的人数dataGridView1.DataSource = ds.Tables["学生信息"];}//查询结果展示到第一个DataGridView控件中,代码如下:DataGridView1.DataSource = DataSet.Table[0]; private void button2_Click(object sender, EventArgs e) //数据筛选{DataView dv = new DataView();dv.Table = ds.Tables[0];dv.RowFilter = "性别='男'"; //筛选出性别为“男”的学生dataGridView2.DataSource = dv;}//通过视图,将所修改记录的当前版本结果展示在第二个“DataGridView”控件中private void button3_Click(object sender, EventArgs e) //数据排序{DataView dv = new DataView();dv.Table = ds.Tables[0];dv.Sort = "学号desc"; //利用视图对数据按照学号进行降序排序dataGridView2.DataSource = dv;}//通过视图,将所修改记录的当前版本结果展示在第二个“DataGridView”控件中private void button4_Click(object sender, EventArgs e)//状态筛选{DataView dv1 = new DataView();dv1.Table = ds.Tables[0];dv1.Sort = "学号asc";int i = -1;i = dv1.Find("200303020107"); //查询学号为“200303020107”学生记录if (i >= 0){dv1.Table.Rows[i]["姓名"] = "计算机"; //将其学生姓名修改为“计算机”}DataView dv2 = new DataView();dv2.Table = ds.Tables[0];dv2.RowStateFilter = DataViewRowState.ModifiedCurrent;dataGridView2.DataSource = dv2;}//通过视图,将所修改记录的当前版本结果展示在第二个“DataGridView”控件中}}8.usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace 数据更新{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e)//“新增专业1”事件{ SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; conn.Open();SqlCommandcomm = new SqlCommand();comm.Connection = conn;mandText = "INSERT INTO 专业(专业编号,专业名称,学制,部门编号) VALUES" + "('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + comboBox1.SelectedText + "')";//通过Sql拼接的方式实现数据新增mandType = CommandType.Text;if (comm.ExecuteNonQuery() > 0)MessageBox.Show("新增成功");//新增的时候令专业编号为1,2conn.Close();}private void button2_Click(object sender, EventArgs e)//“新增专业2”事件{SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; conn.Open();SqlCommandcomm = new SqlCommand();comm.Connection = conn;mandText = "INSERT INTO 专业(专业编号,专业名称,学制,部门编号) VALUES(@专业编号,@专业名称,@学制,@部门编号)";//添加参数,通过参数的方式实现数据新增comm.Parameters.Add("@专业编号", SqlDbType.Char, 4).Value = textBox1.Text;comm.Parameters.Add("@专业名称", SqlDbType.VarChar, 20, "专业名称").Value = textBox2.Text;comm.Parameters.Add("@学制", SqlDbType.TinyInt).Value = textBox3.Text;SqlParameter p = new SqlParameter();p.ParameterName = "@部门编号";p.SqlDbType = SqlDbType.Char;p.Size = 2;p.Value = comboBox1.SelectedItem.ToString();comm.Parameters.Add(p);if (comm.ExecuteNonQuery() > 0)MessageBox.Show("新增成功");conn.Close();}private void button3_Click(object sender, EventArgs e)//“事务输出参数”事件{SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; conn.Open();SqlCommandcomm = new SqlCommand();mandType = CommandType.StoredProcedure;comm.Connection = conn;//调用数据库中的“OutputProcedure”存储过程,并将事务的输出参数值输出mandText = "OutputProcedure";//两个输入参数comm.Parameters.Add("@m1", SqlDbType.Int).Value = 6;comm.Parameters.Add("@m2", SqlDbType.Int).Value = 7;//输出参数SqlParameter pout = new SqlParameter();pout.ParameterName = "@result";pout.SqlDbType = SqlDbType.Int;pout .Direction =ParameterDirection .Output ;comm .Parameters .Add (pout );//返回值//“事务返回值”事件SqlParameterpreturn=new SqlParameter ();preturn .ParameterName ="@r";preturn .SqlDbType =SqlDbType .Int ;preturn.Direction = ParameterDirection.ReturnValue ;comm.Parameters.Add(preturn );comm.ExecuteNonQuery();MessageBox.Show("输出参数为:"+pout .Value .ToString ()+"返回值为:"+preturn .Value .ToString ());//调用数据库中的“OutputProcedure”存储过程,并将事务的返回值输出conn.Close();}private void button5_Click(object sender, EventArgs e){ //将如上新增的两个专业删除SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456";conn.Open();SqlTransactiontran = conn.BeginTransaction();//事务try{{SqlCommandcomm = conn.CreateCommand();mandType = CommandType.Text;mandText = "delete from 专业where 专业编号='1'";//mandText = "delete from 专业where 专业编号='2'"; comm.Transaction = tran;comm.ExecuteNonQuery();}{SqlCommandcomm = conn.CreateCommand();mandType = CommandType.Text;mandText = "update 专业set 学制='4' where 专业编号='0001'";comm.Transaction = tran;comm.ExecuteNonQuery();}// conn.Close();mit();MessageBox.Show("修改成功");}catch(SqlException ex){tran.Rollback();MessageBox.Show(ex.Message );}finally{conn.Close();}}}}9.usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace 更新数据_代码_{public partial class Form1 : Form{public Form1(){InitializeComponent();}private DataTable table; SqlDataAdapter ad;private void button1_Click(object sender, EventArgs e){//通过SqlDataAdapter方式将数据读取到DataTable中,并展示在DataGridView中stringconnStr = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456";string sql = "select * from 部门";ad = new SqlDataAdapter(sql, connStr);table =new DataTable ();ad.Fill(table);this.dataGridView1.DataSource = table;}private void button2_Click(object sender, EventArgs e)//内存修改数据{ //在SQL数据库部门中增加部门编号13,部门名称英语,负责人刘毅,联系电话1122334//实现向DataTable中增加一条记录,修改一条记录,删除一条记录DataRowrowadd = table.NewRow();//新增一行rowadd["部门编号"] = 14;table.Rows.Add(rowadd );DataRow[] rowupdate = table.Select("部门编号=03");//修改部门编号为03的数据if (rowupdate.Length == 1){rowupdate[0]["部门名称"] = "土木系";}DataRow[] rowdelete = table.Select("部门编号=13");//删除部门编号为13的数据if (rowdelete.Length == 1){rowdelete[0].Delete();}}private void button3_Click(object sender, EventArgs e)//写回数据库{ //通过SqlCommandBuilder方式生成SqlDataAdapter其它的命令,并调用Update将内存更改写会到数据库中SqlCommandBuilder cd = new SqlCommandBuilder(ad);ad.Update(table);}}}10.数据绑定usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}DataSetds ;CurrencyManager cm;private void Form1_Load(object sender, EventArgs e){ds = new DataSet();stringconnStr = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456";string sqlS = "select 学号,姓名,性别,班级编号from 学生信息"; SqlDataAdapteradS = new SqlDataAdapter(sqlS, connStr);adS.Fill(ds, "学生信息");string sqlC = "select 班级编号, 班级名称from 班级"; SqlDataAdapteradC = new SqlDataAdapter(sqlC, connStr);adC.Fill(ds, "班级");//复杂绑定this.dataGridView1.DataSource = ds.Tables["学生信息"];//表格控件显示学生信息boBox3.DataSource = ds.Tables["班级"];//组合框comboBox3显示班级编号this .comboBox3 .DisplayMember ="班级名称";boBox3.ValueMember = "班级编号";//简单绑定this.textBox2.DataBindings.Add("Text", ds.Tables["学生信息"], "学号");//文本框textBox2显示学号this.textBox1.DataBindings.Add("Text", ds.Tables["学生信息"], "姓名");//文本框textBox1显示姓名boBox2.DataBindings.Add("Text", ds.Tables["学生信息"], "性别");//组合框comboBox2显示性别boBox3.DataBindings.Add("SelectedValue", ds.Tables["学生信息"], "班级编号");cm = (CurrencyManager)this.BindingContext[ds.Tables["学生信息"]];}private void button1_Click(object sender, EventArgs e)//首记录{cm.Position = 0;}private void button2_Click(object sender, EventArgs e)//前一条记录{cm.Position --;}private void button3_Click(object sender, EventArgs e)//后一条记录{cm.Position ++;}private void button4_Click(object sender, EventArgs e)//尾记录{cm.Position = cm.Count -1;}}}11.二进制数据插入图像usingSystem.Windows.Forms;using System.IO;usingSystem.Data.SqlClient;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button3_Click(object sender, EventArgs e)//插入图片{openFileDialog1.Filter = "JPG files|*.jpg|BMP files|*.bmp";if (openFileDialog1.ShowDialog() == DialogResult.OK){FileStream file = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);byte[] rawdata = new byte[file.Length];//文字用数组存储file.Read(rawdata, 0, (int)file.Length);file.Close();SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; conn.Open();stringsql = "insert into spic values(@name,@pic)";SqlCommandcomm = conn.CreateCommand();mandText = sql;comm.Parameters .Add ("@name",SqlDbType.NVarChar ,50).Value =this.textBox1.Text ; comm.Parameters .Add ("@pic",SqlDbType.Image ).Value =rawdata;comm.ExecuteNonQuery ();conn .Close ();}}private void button1_Click(object sender, EventArgs e)//展示图片{SqlConnection conn = new SqlConnection();conn.ConnectionString = "Data Source=.;Initial Catalog=JWInfo;User ID=sa;Password=123456"; conn.Open();string sql = "select * from spic where studentName='" + this.textBox1.Text + "'"; SqlCommandcomm = conn.CreateCommand();mandText = sql;SqlDataReaderdr = comm.ExecuteReader();//图片if (dr.Read()){byte[] bytes = (byte[])dr["studentPic"];MemoryStreamms = new MemoryStream(bytes);Image i = Image.FromStream(ms);this.pictureBox1.Image = i;}dr.Close();conn.Close();}private void label1_Click(object sender, EventArgs e){ }}}}12.报表usingSystem.Windows.Forms;usingMicrosoft.Reporting.WinForms;namespace WindowsFormsApplication1public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“jWInfoDataSet1.课程信息”中。
用ASP实现网上“五子棋”大赛“五子棋”是大家都非常熟悉的一种益智类游戏,相关的游戏软件也非常多,在此我向大家隆重推出一款新的纯“网络版”的五子棋,它利用ASP做为开发环境,因此在Internet上对战的时候无需下载客户端软件,只要你有一个浏览器就可以了。
你也可以在局域网上进行这个游戏。
对于ASP,我不想做过多的说明,在以前的文章中,我已经说过很多。
游戏的过程是这样的,我们首先登录,然后可以选择战场,有“金星”、“木星”、“水星”、“火星”、“土星”等五个战场,如果你自认为是一个高手,可以选择金星,否则可以依次选择其它几个星球做为战场。
如果这个星球上没有擂主,你就应该以擂主的身份进入,然后别人就可以和你进行对战了。
当然,如果所有的星球上都已经开始了战争,那么你就只能等一会儿了。
如果你是以擂主身份进入的,你可以等待别人来和你对战,如果你是以攻擂手的身份登录,你可以很快的和擂主展开战斗。
开始战斗后,由擂主执黑先行,然后由攻擂手出招,如此这般。
当最后决出胜负的时候,会有相应的提示。
该站点有几个主要的文件是:Index.asp 登录文件:Index0.asp中间文件:Match.asp 比赛文件:Back0.jpg white0.jpg black0.jpg 中间用到的图形文件,分别指的棋盘,白子和黑子,如下图:在程序的初始化的时候,将棋盘上分成若干的表格,将背景图片放入其中,形成一个棋盘,然后在放上一个棋子后,再将图片换上相应的白子或黑子就可以了。
先看看登录文件:<%@ Language=VBScript %><HTML><HEAD><META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"><title>星球大战之“五子连珠”大赛!</title></HEAD><BODY><p align=center><font size=6>星球大战</font></P><table border=1 width=80% align=center><tr><td>星球</td><td>擂主</td><td>大战</td><td>攻擂</td></tr><tr><td>金星</td><td><%if application("first1")="" then%><form action=index0.asp?flag=First1 method=post><INPUT id=text1 name=txtFirst1 size=10><INPUT id=submit1 name=submit1 type=submit value=进入></form><%elseresponse.write application("first1")end if%></td><td>大战</td><td><%if application("second1")="" then%><form action=index0.asp?flag=second1 method=post><INPUT id=text1 name=txtSecond1 size=10><INPUT id=submit1name=submit1 type=submit value=进入></form><%elseresponse.write application("Second1")end if%></td></tr><tr><td>木星</td><td><%if application("first2")="" then%><form action=index0.asp?flag=First2 method=post><INPUT id=text1 name=txtFirst2 size=10><INPUT id=submit1 name=submit1 type=submit value=进入></form><%elseresponse.write application("first2")end if%></td><td>大战</td><%if application("second2")="" then%><form action=index0.asp?flag=second2 method=post><INPUT id=text1 name=txtSecond2 size=10><INPUT id=submit1name=submit1 type=submit value=进入></form><%elseresponse.write application("Second2")end if%></td></tr><tr><td>金星</td><td><%if application("first3")="" then%><form action=index0.asp?flag=First3 method=post><INPUT id=text1 name=txtFirst3 size=10><INPUT id=submit1 name=submit1 type=submit value=进入></form><%elseresponse.write application("first3")end if%></td><td>大战</td><td><%if application("second3")="" then%><form action=index0.asp?flag=second3 method=post><INPUT id=text1 name=txtSecond3 size=10><INPUT id=submit1name=submit1 type=submit value=进入></form><%response.write application("Second3")end if%></td></tr><tr><td>金星</td><td><%if application("first4")="" then%><form action=index0.asp?flag=First4 method=post><INPUT id=text1 name=txtFirst4 size=10><INPUT id=submit1 name=submit1 type=submit value=进入></form><%elseresponse.write application("first4")end if%></td><td>大战</td><td><%if application("second4")="" then%><form action=index0.asp?flag=second4 method=post><INPUT id=text1 name=txtSecond4 size=10><INPUT id=submit1name=submit1 type=submit value=进入></form><%elseresponse.write application("Second4")end if%></td></tr><tr><td>金星</td><td>if application("first5")="" then%><form action=index0.asp?flag=First5 method=post><INPUT id=text1 name=txtFirst5 size=10><INPUT id=submit1 name=submit1type=submit value=进入></form><%elseresponse.write application("first5")end if%></td><td>大战</td><td><%if application("second5")="" then%><form action=index0.asp?flag=second5 method=post><INPUT id=text1 name=txtSecond5 size=10><INPUT id=submit1name=submit1 type=submit value=进入></form><%elseresponse.write application("Second5")end if%></td></tr></table></BODY></HTML>这个文件不用做过多的说明,就是一个大的表格,大家可以从那里进入,如果某个位置已经被使用,则它会变成该大侠的名字,不允许重复登录。
ASP案例──聊天室通过聊天室,可以跟身在远方的好朋友尽情聊天,也可以结交认识网上的很多新朋友。
一、关键技术1.网页的定时刷新在聊天室中,浏览器要不停地刷新,以读取最新的用户发言。
可用实现语句:<meta http-equiv=”refresh” content=3>实例:<html><head><meta http-equiv="refresh" content="1"><title>网页定时刷新</title></head><body><font color=red size=5><center>现在时间是:<%=now()%><center></font></body></html>2.使用Application和Session对象刷新聊天室Application对象代表了一个Action Server应用程序,也就是一个Web网页,Session对象则表示一个用户,代表一个用户对这个页面的一次访问,通过Application对象可以让访问它的所有用户共享信息,并可以在Web服务器运行期间持久地保存数据,而Session对象也可以在用户的一次访问期间持久地保持数据。
3.私聊私聊只要求发言者和发言对象看到聊天的内容,当然,当私聊的对象是所有人时,则所有的人都能看到私聊的内容。
二、模块构成1.用户登录模块。
2.新用户注册模块。
3.已注册用户聊天模块。
二、文件组成1.用户登录模块Index.asp,即系统登录默认页面。
2.用户注册模块Register.asp。
3.已注册用户聊天模块。
聊天室主界面:Main.asp聊天室布局:ChatRoom.asp显示当前在线用户名单:ShowName.asp实现用户输入和发送聊天内容:PostMsg.asp显示用户登录之后的所有聊天内容:ShowMsg.asp在聊天室主界面上方显示该聊天室的名称:TopMsg.asp用户退出登录:Logout.asp4.公共文件:与数据连接:Conn.asp用户密码的加密:MD5.asp邮件地址格式确认:Procedure.asp验证码的生成与显示:Function.asp、SafeCode.asp、Canvas.asp、Font.asp。
超精华的asp代码⼤全显⽰页⾯加载时间重复域中的斑马线显⽰字符串前20个字符并在结尾处添加“……”如果动态图⽚为空,使⽤默认图⽚代替如果数据为空,使⽤默认提⽰信息代替显⽰页⾯加载时间页⾯顶部添加下⾯的代码:<%Dim strStartTimeDim strEndTimestrStartTime = Timer '开始时间%>页⾯(同⼀页)的末尾添加:<%' 加载完毕的时间strEndTime = TimerResponse.Write ("页⾯加载时间: ")Response.Write FormatNumber(strEndTime - strStartTime, 4)Response.Write (" 秒.")%>重复域中的斑马线<%'此模块放置在重复域之外Dim RecordCounterRecordcounter = 0%><tr class =<%'将重复域中第⼀个 <tr>标签的CLASS属性代码⽤本模块替换'本模块基于CSS来改变单元格背景⾊,你也可以直接设置背景⾊来实现斑马线RecordCounter = Recordcounter + 1If RecordCounter Mod 2 = 1 ThenResponse.Write "altRow1"ElseResponse.write "altRow2"End If%>显⽰字符串前20个字符并在结尾处添加“……”<%Dim CutShortCutShort = rsYourRecordset.Fields.Item("YourField").ValueResponse.Write LEFT (CutShort, 20) & "........"%>如果动态图⽚为空,⽤默认图⽚代替<%Dim PicShowPicShow = rsShowHide.Fields.Item("shMainPix").ValueIF PicShow <>"" THEN %><img src="<%=rsShowHide.Fields.Item("shMainPix").Value%>"><% ELSE %><img src="StaticPic.gif"><% End If %>如果数据为空,⽤默认提⽰信息代替。
asp源代码
ASP(Active Server Pages)是一种基于服务器端的脚本语言,用于创建动态网页和应用程序。
本文将探讨ASP源代码的基本概念、语法和用法,并提供一些示例以帮助读者更好地理解和应用ASP。
ASP源代码是在ASP文件中编写的。
ASP文件可以包含HTML标记和ASP脚本。
ASP脚本通过包含在尖括号<% %>内部来识别。
在这些标记中,可以编写各种ASP代码,如变量声明、条件语句、循环语句、函数和对象等。
在ASP中,可以使用各种对象和组件来完成各种任务。
例如,可以使用Request对象来获取来自客户端的数据,使用Response对象向客户端发送数据。
还可以使用Server对象访问服务器上的一些属性和方法。
此外,还可以使用Session和Application对象来处理会话和应用程序级别的数据。
下面是一些ASP源代码的示例:
1. 变量声明和输出:
<%
Dim name name = \。
asp常用代码大全x1、ASP开始结束符语法:< % %> 文件后缀.asp2、判断语句:判断表单传来的用户名和密码是否正确,并提示If request("username")="admin" thenResponse.write"恭喜,你已经登录成功"ElseResponse.write"对不起,您输入的用户名错误,请返回重输入"End ifIf request("name")="admin" and request("pass")="admin"thenResponse.redirect"admin.asp"ElseResponse.redirect"login.asp"End if3、循环语句:循环显示6条数据库中的记录写法1:for n=1 to 6response.write rs("title")&"< br>"if not rs.eof thenexit forelsers.movenextend ifnext写法二:do while not rs.eofresponse.write rs("title")&"< br>"rs.movenextloop4、常用变量转换函数:Now() 函数返回系统时间Date() 函数返回当前系统日期.CStr(int) 函数转化一个表达式为字符串CInt(string) 将一个表达式转化为数字类型Trim(request("username")) 函数去掉字符串左右的空格Left(rs("title"),10) 函数返回字符串左边第length个字符以前的字符(含第length个字符),一般在限制新闻标题的显示长度的时候用Len(string) 函数返回字符串的长度.5、Access数据库连接代码方法一:db="mydata.mdb" ‘如果放在目录中,就要写明"database/mydata.mdb"Set conn = Server.CreateObject("ADODB.Connection")connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)conn.Open connstr方法二:'如果你的服务器采用较老版本Access驱动,请用下面连接方法db="mydata.mdb" ‘如果放在目录中,就要写明"database/mydata.mdb"Set conn = Server.CreateObject("ADODB.Connection")connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)conn.Open connstr6、Recordset对象操作数据库语法(1)打开sql语句指定的表中的数据,把这批数据放入rs对象中取出news表中所有的数据放到rs中Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,1取出news表中前6条数据放到rs中Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 6 * from news"Rs.Open SqlStr,conn,1,1(2)循环显示6条rs对象中存在的数据,列表显示不带连接的写法for n=1 to 6response.write rs("title")&"< br>"if not rs.eof thenexit forelsers.movenextend ifnext带连接的写法for n=1 to 6response.write "< a href=show.asp?id=rs("id")>"& left(rs("title"),20)&"< /a>< br>"if not rs.eof thenexit forelsers.movenextend ifnext(3)向数据库添加一条数据代码Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表Rs.addnewRs("title")=trim(request("title"))Rs("neirong")=request("neirong")Rs("date")=now()rs.update ‘真正写入数据库(4)修改一条记录的代码,通过(2)中的连接传递过来了id数值Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表Rs("title")=trim(request("title"))Rs("neirong")=request("neirong")Rs("date")=now()rs.update ‘真正写入数据库(5)删除数据库中一条记录,通过连接传递过来了数据得id数值Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘注意这里的1,3代表可以写入的打开数据表rs.delete ‘删除该条数据7、标准Sql语句写法包括取全部记录Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news"Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把数据提出到rs对象中选取几条数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 6 * from news"Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把6条数据提出到rs 对象中选取一条指定表中id字段数值的数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select * from news where id="&request("id")Rs.Open SqlStr,conn,1,1 ‘运行sql语句,把6条数据提出到rs 对象中添加一条表单传过来的数据替换Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="insert into news(title,neirong) values(request("title"), request("neirong"))修改一条指定表中id字段数值的数据,用表单传过来的数据替换Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="update news set title=’"&request("title")&"’,neirong=’"&request("内容")&"’ where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘运行sql语句,把数据提出到rs对象中删除一条指定表中id字段数值的数据Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="delete from news where id="&request("id")Rs.Open SqlStr,conn,1,3 ‘运行sql语句,把数据提出到rs对象中8、当点击按钮时候表单带着的数据传送到哪个文件,在哪里指定?< form method="post" action="addsave.asp">< input type="text" name="title">< input type="text" name="neirong">< input type="submit" name="Submit" value="提交">< /form>9、表单提交来的数据接收并显示到屏幕上的代码response.write request("name")response.write now()response.write trim(request("name"))10、利用Application对象作计数器的语法在网页的头部加入Application.LockApplication("counter") = Application("counter") + 1Application.UnLock在需要显示计数内容的网页的地方,加入下面的语句response.write Application("counter")11、利用Session对象保护后台管理页面admin.asp,防止未登陆用户进入在网站后台网页admin.asp的头部加入下面的代码,if session(admin)< >"ok" thenresponse.redirect"login.asp"response.endend if在网站后台登陆页的密码验证部分标准写法AdmName=Request.Form("Name")AdmPass=Request.Form("Pass")Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="Select * from Admin where name='"&AdmName&"' and pass='"&AdmPass&"'"Rs.Open SqlStr,conn,1,3if Rs.EOF AND RS.BOF thenResponse.Redirect("login.asp")response.endelsesession("admin")="ok"Response.Redirect("admin.asp")response.endend if12、分页代码sql = "select……………………省略了sql语句Set rs=Server.Createobject("ADODB.RECORDSET")rs.Open sql, conn, 1, 1if not rs.eof thenpages = 30 '定义每页显示的记录数rs.pageSize = pages '定义每页显示的记录数allPages = rs.pageCount '计算一共能分多少页page = Request.QueryString("page")'通过浏览器传递的页数’if语句属于基本的排错处理if isEmpty(page) or Cint(page) < 1 thenpage = 1elseif Cint(page) > allPages thenpage = allPagesend ifrs.AbsolutePage = pageDo while not rs.eof and pages > 0'这里输出你要的内容………………pages = pages - 1rs.MoveNextLoopelseResponse.Write("数据库暂无内容!")End ifrs.CloseSet rs = Nothing分页页码连接和跳转页码程序< form Action="v3.asp" Method="GET">< %If Page < > 1 ThenResponse.Write "< A HREF=?Page=1>第一页< /A>"Response.Write "< A HREF=?Page=" & (Page-1) & ">上一页< /A>"End IfIf Page < > rs.PageCount ThenResponse.Write "< A HREF=?Page=" & (Page+1) & ">下一页< /A>"Response.Write "< A HREF=?Page=" & rs.PageCount & ">最后一页< /A>"End If%>< p>输入页数:< input TYPE="TEXT" Name="Page" SIZE="3"> 页数:< font COLOR="Red">< %=Page%>/< %=rs.PageCount%>< /font> < /p>< /form>13、分行列显示图片和产品名称的代码(4列x3行=12个)< %Set Rs=Server.CreateObject("ADODB.RecordSet")SqlStr="select top 12 * from myproduct"Rs.Open SqlStr,conn,1,1i=1%>< table width="90%" border="1" cellspacing="0" sellpadding="0">< tr>< %do while not rs.eof%>< td align="center">< img src="< %=rs("imgurl")%>" width="52" height="120">< br>< %=rs("productname")%>< /td>< % if i mod 4=0 then response.write"< /tr>< tr>"i=i+1rs.movenextlooprs.close%>< /tr>< /table>14、ASP数据库连接之ACCESS-SQLSERVER< %IsSqlData=0 定义数据库类别,0为Access数据库,1为SQL 数据库If IsSqlData=0 ThenAccess数据库datapath ="data/" 数据库目录的相对路径datafile ="data.mdb" 数据库的文件名connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&Server.MapPath(""&datapath&""&datafile&"") Connstr="DBQ="&server.mappath(""&datapath&""&datafil e&"")&";DRIVER={Microsoft Access Driver (*.mdb)};"ElseSQL数据库SqlLocalName ="(local)" 连接IP [ 本地用 (local) 外地用IP ] SqlUsername ="sa" 用户名SqlPassword ="1" 用户密码SqlDatabaseName="data" 数据库名ConnStr = "Provider=Sqloledb;User ID=" & SqlUsername & "; Password=" & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"END IFOn Error Resume NextSet conn=Server.CreateObject("ADODB.Connection")conn.open ConnStrIf Err Thenerr.ClearSet Conn = NothingResponse.Write "数据库连接出错,请检查连接字串。
17个ASP编程基础典型代码日期:2009-10-18 21:16:57点击:30来自:互联网1.ASP取得表格输入数据的方法:GET POST一.get:用户端将数据加到URL后,格式为”?字段1=输入数据1&字段2=输入数据2&...", 再将其送到服务器。
如: action为, 字段Name输入数据为jack,字段age的数据为15,则用get方法为?Name=jack&Age=15二.post:用户端用http信息数据传送到服务器ASP中:get:使用“输入数据=Request.QueryString("字段名")",将附加于URL的数据取出。
post:使用“输入数据=Request.Forml"(字段名")",读取HTTP信息数据字段。
* Request.QueryString范例如:〈A hery="aspform.asp?Name=jack&Age=15"> 按此〈/A〉〈p〉Name:<%=request.QueryString("Name")%) Age:<%=request.QeueryString("Age")%) * get 范例·aspturm.asp: <form action="asp1b.asp" method="get"> 姓名: <input type=textname="input1" value="Your name"> <p> 特征: <select name="input2"> <option>cool!<option>handsome <option>warmhearted </select> <input type=submit value="ok"> </form> asp1b.asp的内容<html><body> <% =request.querystring("input1") %> hi, your character is <%= request.querystring("input2") %></body></html>2.request.From 语法:request.From(name)[(index)|.count] name:字段名index:当同一字段输入多个值时,指针值index指定要读取同一字段的那一个值,范围由1到request.From(name).count count:由request.From(name).count可知name字段输入几个值,若无此name字段,count为0如下例:<% forI=1 to request.fron("input1").count response.writerequest.From("input1")(I)&"<br>" next %> 若input1有两个值则都显示出*若未采用index指定读取哪个.可用〈% for each item request.From("input")) repomse.write item &"<br>" next %> 也可用" for each x in tewuest.From"重复取得所有字段的输入值。
一、ASP 编程中 20 个非常有用的例子1. 如何用Asp判断你的网站的虚拟物理路径使用Server.Mappath方法<p align="center"><font size="4" face="Arial"><b>虚拟物理路径为: </b></font><font color="#FF0000" size="6" face="Arial"><%= Server.MapPath("\")%></font></p>显示结果:虚拟物理路径为: G:\homepage\jsjx (与服务器有关)2.如何知道使用者所用的浏览器?使用Request object方法strBrowser=Request.ServerV ariables("HTTP_USER_AGENT")Response.write strBrowser显示结果:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;.NET CLR 1.1.4322;.NET CLR 1.0.3705)3. 如何计算每天的平均反复访问人数解决方法<% ' usercnt为网站点击总数startdate=DateDiff("d",Now,#01/01/2005#)if strdate<0 then startdate=startdate*-1avgvpd=Int((usercnt)/startdate) %><% Response.write (avgvpd) %>显示结果:从2005-1-1号以后的平均日访问人数4.如何显示随机图象<% dim p,ppic,dpicppic=12randomizep=Int((ppic*rnd)+1)dpic="graphix/randompics/"&p&".gif"%>显示<img src="<%=dpic%>">5.如何回到先前的页面<a href="<%=request.ServerV ariables("Http_REFERER")%>">preivous page</a> 或用图片如:<img src="arrowback.gif"alt="<%=request.ServerV ariables("HTTP_REFERER")%>">6.如何确定对方的IP地址<%=Request.ServerV ariables("REMOTE_ADDR)%>7.如何链结到一副图片上<% @Languages=vbs cript %><% Response.expires=0strimagename="graphix/errors/erroriamge.gif"Response.redirect(strimagename)%>8.强迫输入网络密码对话框把这句话放在页面的开头,就会弹出“输入网络密码”对话框<% Response.status="401 not Authorized"Response.end%>9.如何传递变量从一页到另一页用HIDDEN 类型来传递变量<% form method="post" action="mynextpage.asp"><% for each item in request.form %><input namee="<%=item%>" type="HIDDEN"value="<%=Server.HTMLEncode(Request.form(item)) %>"><% next %></form>10.为何在asp 程序内使用msgbox,程序出错说没有权限由于asp 是服务器运行的,如果可以在服务器显示一个对话框,那么只好等有人按了确定之后,你的程序才能继续执行,而一般服务器不会有人守着,所以微软不得不禁止这个函数,并胡乱告诉你(:) 呵呵) 没有权限。
但是ASP和客户端脚本结合倒可以显示一个对话框: <% yourVar="测试对话框"%><%Script language='javascript'>alert("<%=yourvar%>")</s cript>11.有没有办法保护自己的源代码,不给人看到可以去下载一个微软的Windows script Encoder,它可以对asp的脚本和客户端javascript/vbs cript脚本进行加密。
不过客户端加密后,只有ie5才能执行,服务器端脚本加密后,只有服务器上安装有Script engine 5(装一个ie5就有了)才能执行。
12.怎样才能将Querystring 从一个asp 文件传送到另一个?前者文件加入下句:Response.Redirect("second.asp?" &Request.ServerVariables("QUERY_STRING"))13.global.asa文件总是不起作用?只有web目录设置为web application, global.asa才有效,并且一个web application的根目录下global.asa才有效。
IIS4可以使用Internet Service Manager设置application setting ,这样才能使得htm文件如同asp文件一样可以执行脚本代码。
14.怎样才能使得htm文件如同asp文件一样可以执行脚本代码?Internet Sevices Manager -> 选择default web site ->右鼠键->菜单属性-〉主目录-> 应用程序设置(Application Setting)-> 点击按钮"配置"-> app mapping ->点击按钮"Add" -> executable browse选择\WINNT\SYSTEM32\INETSRV\ASP.DLL EXTENSION 输入htm method exclusions 输入PUT.DELETE 全部确定即可。
但是值得注意的是这样对htm也要由asp.dll 处理,效率将降低。
15.如何注册组件有两种方法。
第一种方法:手工注册DLL 这种方法从IIs 3.0一直使用到IIs 4.0和其它的Web Server。
它需要你在命令行方式下来执行,进入到包含有DLL的目录,并输入:regsvr32 component_name.dll 例如c:\temp\regsvr32 AspEmail.dll 它会把dll的特定信息注册入服务器中的注册表中。
然后这个组件就可以在服务器上使用了,但是这个方法有一个缺陷。
当使用这种方法注册完毕组件后,该组件必须要相应的设置NT的匿名帐号有权限执行这个dll。
特别是一些组件需要读取注册表,所以,这个注册组件的方法仅仅是使用在服务器上没有MTS 的情况下,要取消注册这个dll,使用:regsvr32 /u aspobject.dll example c:\temp\regsvr32 /u aneiodbc.dll第二种方法:使用MTS(Microsoft Transaction Server) MTS是IIS 4新增特色,但是它提供了巨大的改进。
MTS允许你指定只有有特权的用户才能够访问组件,大大提高了网站服务器上的安全性设置。
在MTS上注册组件的步骤如下:1) 打开IIS管理控制台。
2) 展开transaction Server,右键单击"pkgs installed"然后选择"new package"。
3) 单击"create an empty package"。
4) 给该包命名。
5) 指定administrator帐号或则使用"interactive"(如果服务器经常是使用administrator 登陆的话)。
6) 现在使用右键单击你刚建立的那个包下面展开后的"components"。
选择"new then component"。
7) 选择"install new component" 。
8) 找到你的.dll文件然后选择next到完成。
要删除这个对象,只要选择它的图标,然后选择delete。
附注:特别要注意第二种方法,它是用来调试自己编写组件的最好方法,而不必每次都需要重新启动机器了。
16. ASP与Access数据库连接:<%@ language=VBscript%><%dim conn,mdbfilemdbfile=Server.mappath("数据库名称.mdb")set conn=Server.Ceateobject("adodb.connection")conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&mdbfile%>17. ASP与SQL数据库连接:<%@ language=VBs cript%><%dim connset conn=Server.Createobject("ADODB.connection")sqlstring="Provider=SQLOLEDB;database=数据库名称;UID=sa;Pwd=数据库密码" Conn.ConnectionString =sqlstring%>建立记录集对象:set rs=Server.createobject("adodb.recordset")rs.open SQL语句,conn,3,218. SQL常用命令使用方法:(1) 数据记录筛选:sql="select * from 数据表where 字段名=字段值order by 字段名[desc]"sql="select * from 数据表where 字段名like '%字段值%' order by 字段名[desc]" sql="select top 10 * from 数据表where 字段名order by 字段名[desc]"sql="select * from 数据表where 字段名in ('值1','值2','值3')"sql="select * from 数据表where 字段名between 值1 and 值2"(2) 更新数据记录:sql="update 数据表set 字段名=字段值where 条件表达式"sql="update 数据表set 字段1=值1,字段2=值2 ……字段n=值n where 条件表达式"(3) 删除数据记录:sql="delete from 数据表where 条件表达式"sql="delete from 数据表" (将数据表所有记录删除)(4) 添加数据记录:sql="insert into 数据表(字段1,字段2,字段3 …) valuess (值1,值2,值3 …)"sql="insert into 目标数据表select * from 源数据表" (把源数据表的记录添加到目标数据表)(5) 数据记录统计函数:A VG(字段名) 得出一个表格栏平均值COUNT(*|字段名) 对数据行数的统计或对某一栏有值的数据行数统计MAX(字段名) 取得一个表格栏最大的值MIN(字段名) 取得一个表格栏最小的值SUM(字段名) 把数据栏的值相加引用以上函数的方法:sql="select sum(字段名) as 别名from 数据表where 条件表达式"set rs=conn.excute(sql)用rs("别名") 获取统的计值,其它函数运用同上。