首先,必须要使用打开数据库方法:
<% dim objconn,objconnstr set objconn=server.createobject("adodb.connection") objconnstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data/data.mdb") objconn.open objconnstr %>
1、添加数据库表
<% dim sql sql="Create Table colin(id counter primary key,company text,addr text,dep text,contacts text,phone text,casename text,caseid int,qs_inf text,qs_wt text,isdel bit,createtime datetime)" objconn.execute(sql) objconn.Close response.Write("添加完成") %>
2、查询表字段
<%dim sql,rs1 set rs1=server.CreateObject("Adodb.recordset") sql="select top 1 * from colin" rs1.open sql,objconn,1,2 For i=0 To rs1.fields.count-1 t=rs1.fields(i).name response.Write(t&"<br />") next %>
3、添加表字段
<%dim sql sql="alter table colin add column news_id int" objconn.execute(sql) %>
删除表字段:alter table 表名 drop column 字段名
4、修改表字段类型
<%dim sql sql="alter table colin alter column exhi_img text(200)" objconn.execute(sql) %>
5、向数据库表添加数据
<% dim a,b,c,d a=1 b=2 c=3 d=4 dim rs,sql set rs=server.CreateObject("adodb.recordset") sql="select * from colin" rs.open sql,objconn,1,2 rs.addnew() rs("a")=a rs("b")=b rs("c")=c rs("d")=d rs("createtime")=now() rs.update() rs.close response.Write("<script language='javascript'>alert('您已成功提交表单')</script>") %>
6、删除数据库表数据
<% dim sql sql="delete from colin where id="5" and isdel=true" objconn1.execute(sql) response.Redirect("adminbranch.asp") %>
<%dim sql sql="delete from colin where id BETWEEN 3 and 3000" objconn.execute(sql) response.Write("删除成功") %>
7、查询并列出数据库表数据
<%dim rspic,sqlpic set rspic=server.CreateObject("adodb.recordset") sqlpic="select * from colin order by createtime desc" rspic.open sqlpic,objconn,0,1 if not rspic.eof then do while not rspic.eof %> <tr><td align="center"><%=rspic("a")%></td><td align="center"><%=rspic("b")%></td><td align="center"><%=rspic("c")%></td><td align="center"><%=rspic("d")%></td></tr> <%rspic.movenext loop%> <%end if%>
-完-