在ASP中如何运用SQL查询.(100分)

  • 主题发起人 主题发起人 zhukairu
  • 开始时间 开始时间
Z

zhukairu

Unregistered / Unconfirmed
GUEST, unregistred user!
希望各位大哥给个完整的过程
如建立数据库连接,在之后用SQL调用,进行查询.
 
老大,这不是几句话就能说完的,还是找本书系统的看看吧
 
set conn1=server.createobject("ADODB.connection")
db="driver={microsoft access driver(*.mdb)};dbq="&server.mappath("db.mdb")
sql=conn1.open db
之后的插入,查询,以及最后的结束语,这些我都忘了。
只想有人提醒我一下:)
谢谢
 
set conn1=server.createobject("ADODB.connection")
db="driver={microsoft access driver(*.mdb)};dbq="&server.mappath("db.mdb")
set rst=conn1.Execute("select top 10 * from tablename")
 
DW MX自己生成的。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/newsConn.asp" -->
<!--#include virtual="/news/function.asp"-->
<%
function HTMLEncode(fString)
fString = replace(fString, ">", "&amp;gt;")
fString = replace(fString, "<", "&amp;lt;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) &amp;
CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode = fString
end function
%>
<%
Dim rst_getNews__MMColParam
rst_getNews__MMColParam = "1"
If (Request.QueryString("newsID") <> "") then

rst_getNews__MMColParam = Request.QueryString("newsID")
End If
%>
<%
Dim rst_getNews
Dim rst_getNews_numRows
Set rst_getNews = Server.CreateObject("ADODB.Recordset")
rst_getNews.ActiveConnection = MM_newsConn_STRING
rst_getNews.Source = "SELECT * FROM news_tab WHERE newsID = " + Replace(rst_getNews__MMColParam, "'", "''") + ""
rst_getNews.CursorType = 0
rst_getNews.CursorLocation = 2
rst_getNews.LockType = 1
rst_getNews.Open()
rst_getNews_numRows = 0
%>
<%
dj(Request("newsID"))
%>
<HTML><HEAD><TITLE>:::|平凉信息港|:::----------<%=(rst_getNews.Fields.Item("newsTitle").Value)%></TITLE>
<META http-equiv=Content-Type content="text/html;
charset=gb2312">
<STYLE type=text/css>TD {
FONT-SIZE: 12px
}
div {
FONT-SIZE: 12px
}
LI {
FONT-SIZE: 12px
}
SELECT {
FONT-SIZE: 12px
}
INPUT {
FONT-SIZE: 12px
}
.l7 {
LINE-HEIGHT: 170%
}
.w7 {
FONT-SIZE: 7px
}
.f7 {
FONT-SIZE: 7px
}
.f9 {
FONT-SIZE: 12px
}
.f24 {
FONT-SIZE: 24px
}
.f14 {
FONT-SIZE: 14px;
LINE-HEIGHT: 150%
}
.9b {
FONT-SIZE: 9pt;
COLOR: #000000;
LINE-HEIGHT: 150%;
FONT-FAMILY: "宋体"
}
A:link {
FONT-SIZE: 9pt;
COLOR: #333333;
FONT-FAMILY: "宋体";
TEXT-DECORATION: none
}
A:visited {
FONT-SIZE: 9pt;
COLOR: #333333;
FONT-FAMILY: "宋体";
TEXT-DECORATION: none
}
A:hover {
FONT-SIZE: 9pt;
COLOR: #cc0000;
FONT-FAMILY: "宋体";
TEXT-DECORATION: none
}
A:active {
FONT-SIZE: 9pt;
COLOR: #cc0000;
TEXT-DECORATION: none
}
.b {
FONT-SIZE: 9pt;
COLOR: #333333;
LINE-HEIGHT: 150%;
FONT-FAMILY: "宋体"
}
A.b:link {
FONT-SIZE: 9pt;
COLOR: #333333;
TEXT-DECORATION: none
}
A.b:visited {
FONT-SIZE: 9pt;
COLOR: #333333;
TEXT-DECORATION: none
}
A.b:hover {
FONT-SIZE: 9pt;
COLOR: #cc0000;
TEXT-DECORATION: none
}
A.b:active {
FONT-SIZE: 9pt;
COLOR: #cc0000;
TEXT-DECORATION: none
}
</STYLE>
<SCRIPT language=JavaScript>
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a&amp;&amp;i<a.length&amp;&amp;(x=a)&amp;&amp;x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document;
if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
for(i=0;
i<a.length;
i++)
if (a.indexOf("#")!=0){ d.MM_p[j]=new Image;
d.MM_p[j++].src=a;}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x;
if(!d) d=document;
if((p=n.indexOf("?"))>0&amp;&amp;parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);}
if(!(x=d[n])&amp;&amp;d.all) x=d.all[n];
for (i=0;!x&amp;&amp;i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&amp;&amp;d.layers&amp;&amp;i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x &amp;&amp;
d.getElementById) x=d.getElementById(n);
return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments;
document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x;
if(!x.oSrc) x.oSrc=x.src;
x.src=a[i+2];}
}
//-->
</SCRIPT>
<script Language="JavaScript" src="/js/pop.js"></script>
<script Language="JavaScript" src="js/main/roll.js"></script>
<SCRIPT language=JavaScript>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&amp;&amp;(parseInt(appVersion)==4)) {
do
cument.MM_pgW=innerWidth;
document.MM_pgH=innerHeight;
onresize=MM_reloadPage;
}}
else
if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</SCRIPT>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff >
<!--#include virtual="/head.htm"--><br>
<TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
<TBODY>
<TR>
<TD height=2>
<P><IMG height=4 src="" width=760></P></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
<TBODY>
<TR>
<TD background="">
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD vAlign=top width=162>
<TABLE class=9b cellSpacing=0 cellPadding=0 width="99%" align=center
border=0>
<TBODY>
<TR>
<TD><IMG height=6 src="" width=6></TD></TR>
<TR>
<TD bgColor=#000000 height=18>
<DIV align=center><FONT color=#ffffff>&amp;lt;&amp;lt;
内 容 搜 索
&amp;gt;&amp;gt;
</FONT></DIV></TD></TR>
<TR>
<TD height=13>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=left
border=0>
<TBODY>
<TR>
<TD height=2><IMG height=10 src="" width=6></TD></TR>
<TR>
<TD height=49>
<TABLE cellSpacing=0 cellPadding=2 width=130
align=center border=0>
<FORM name=search_form method="post" action="searchNews.asp">
<TBODY>
<TR>
<TD>
<DIV align=center><BR>
<INPUT class=a01 maxLength=256 size=16
name=search> </DIV></TD></TR>
<TR>
<TD>
<DIV align=center><INPUT type=submit value="搜 索" name=submit>
<INPUT type=reset value="重 置" name=Submit>
</DIV></TD></TR>
<TR>
<TD></TD></TR></FORM></TBODY></TABLE></TD></TR>
<TR>
<TD height=2><IMG height=10 src=""
width=6></TD></TR></TBODY></TABLE><IMG height=6 src=""
width=6></TD></TR>
<TR>
<TD bgColor=#0066cc height=18>
<DIV align=center><FONT color=#ffffff>最 近 更 新</FONT></DIV></TD></TR>
<TR>
<TD vAlign=top>
<TABLE class=b cellSpacing=0 cellPadding=0 width="96%"
align=center border=0>
<TBODY>
<TR>
<TD height=2><IMG height=10 src="" width=6></TD></TR>
<TR>
<TD height=49><%getNew(7)%> </TD>
</TR>
<TR>
<TD height=2><IMG height=10 src=""
width=6></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#fddc01 height=18>
<DIV align=center><FONT color=#003366><FONT color=#000000>点
击 排 行</FONT> </FONT></DIV></TD></TR>
<TR>
<TD>
<TABLE class=b cellSpacing=0 cellPadding=0 width="96%"
align=center border=0>
<TBODY>
<TR>
<TD height=2><IMG height=10 src="" width=6></TD></TR>
<TR>
<TD height=49><%getdj(7)%> </TD>
</TR>
<TR>
<TD height=2><IMG height=10 src=""
width=6></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top align=middle width=598>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=2></TD></TR>
<TR>
<TD align=right>
<TABLE cellSpacing=1 cellPadding=0 width="98%" bgColor=#000000
border=0>
<TBODY>
<TR>
<TD bgColor=#ffffff>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD bgColor=#cc0000 height=6></TD></TR>
<TR>
<TD bgColor=#000000 height=2></TD></TR>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="97%"
align=center border=0>
<TBODY>
<TR>
<TD height=15></TD></TR>
<TR>
<TD height=6>
<DIV align=center><B
class=f24><%=(rst_getNews.Fields.Item("newsTitle").Value)%></B></DIV></TD></TR>
<TR>
<TD
height=11 background="/news/bj_2.gif" ></TD></TR>
<TR>
<TD class=9b>
<DIV class=f24 align=center></DIV>
<DIV class=f9 align=center><SPAN class=9b>加入时间:<FONT
color=#666666><%=(rst_getNews.Fields.Item("postDate").Value)%> </FONT> 文章来源:<font color="#666666"><%=(rst_getNews.Fields.Item("auther").Value)%></font>点击次数:<FONT
color=#666666><%=(rst_getNews.Fields.Item("dj").Value+1)%></FONT></SPAN></DIV>
<br>
<img src="/news/ad/images/<!--#include virtual="/news/ad/adRotator.asp"-->.gif" border="0" align="left"><FONT class=f14
style="FONT-SIZE: 14px;
LINE-HEIGHT: 130%"><%=HTMLEncode(rst_getNews.Fields.Item("news").Value)%></FONT>
<P class=9b align=right>【 <A href="javascript:if%20(window.print%20!=%20null)%20{%20window.print();%20}%20else
%20{%20alert('Your%20browser%20does%20not%20support%20this%20feature.%20Please%20select%20Print%20from%20the%20File%20menu.');%20}">打印本页</A>】 【 <A href="javascript:window.close()">关闭窗口</A>】</P></TD></TR>
<TR>
<TD height=11></TD></TR>
<TR>
<TD height=6></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#000000 height=2></TD></TR>
<TR>
<TD bgColor=#cc0000
height=2></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=right>&amp;nbsp;
</TD></TR>
<TR>
<TD align=right>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD bgColor=#eeeeee height=18><FONT
color=#003366>&amp;nbsp;&amp;nbsp;<FONT color=#000000><B>相
关 文 章</B></FONT></FONT></TD></TR>
<TR>
<TD>
<TABLE class=b cellSpacing=0 cellPadding=0 width="96%"
align=center border=0>
<TBODY>
<TR>
<TD height=2><IMG height=10 src="" width=6></TD></TR>
<TR>
<TD height=49><%call getxg(rst_getNews.Fields.Item("keyWord").Value,5)%>
</TD>
</TR>
<TR>
<TD height=2><IMG height=10 src=""
width=6></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD class=9b bgColor=#eeeeee height=18>&amp;nbsp;&amp;nbsp;<B></B></TD></TR>
<TR>
<TD>
<TABLE class=f9 cellSpacing=0 cellPadding=0 width="96%"
align=center border=0>
<TBODY>
<TR>
<TD height=2><IMG height=10 src="" width=6></TD></TR>
<TR>
<TD height=49>&amp;nbsp;</TD>
</TR>
<TR>
<TD height=2><IMG height=10 src=""
width=6></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD>&amp;nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE id=Table24 cellSpacing=0 cellPadding=0 width=760 align=center border=0>
<TBODY>
<TR>
<TD height=1>
<P align=center></P></TD></TR>
<TR>
<TD bgColor=#216600 height=1></TD></TR>
<TR>
<TD height=11>
<DIV align=center> </DIV></TD></TR></TBODY></TABLE>
<p><!--#include virtual="/bottom.htm"--></p>
</BODY></HTML>
<%
rst_getNews.Close()
Set rst_getNews = Nothing
%>
 
将此文件存为xxingconn.asp (连接Access文件)
<%dim conn
dim connstr
call conn_init()
sub conn_init()
'on error resume next
connstr = "DBQ=" + server.mappath("Exam.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
'response.write connstr
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
end sub
sub endConn()
conn.close
set conn=nothing
end sub
%>

调用xxingconn.asp
set rs=server.createobject("adodb.recordset")
'写Sql
SQL = "Select * From record where boardid="+cstr(bid)+" and stdname='"+pname+"'"
'打开通道
RS.Open SQL,conn,1,3
 
去下个教程吧!
看看就明白
 
后退
顶部