【100分求教】asp网站如何从数据库中读取重复数据,满意加分

【100分求教】asp网站如何从数据库中读取重复数据,满意加分,第1张

在Access中建立数据库 db1.mdb 保存在根目录下,在建立一个表为:“表1”

字段名称为:id nume sex age socre

建立一个a.asp页面,在页面中输入代码:<br>

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%

' FileName="Connection_ado_conn_string.htm"

' Type="ADO"

' DesigntimeType="ADO"

' HTTP="false"

' Catalog=""

' Schema=""

Dim MM_conn_STRING

MM_conn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=D:\wwwroot\db1.mdbMode=ReadWritePersist Security Info=False"

'D:\wwwroot\db1.mdb,数据库路径

%>

<%

Dim Recordset1__MMColParam

Recordset1__MMColParam = "1"

If (Request.QueryString("1") <>"") Then

Recordset1__MMColParam = Request.QueryString("1")

End If

%>

<%

Dim Recordset1

Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")

Recordset1.ActiveConnection = MM_conn_STRING

Recordset1.Source = "SELECT * FROM 表1 WHERE id >= " + Replace(Recordset1__MMColParam, "'", "''") + ""

Recordset1.CursorType = 0

Recordset1.CursorLocation = 2

Recordset1.LockType = 1

Recordset1.Open()

Recordset1_numRows = 0

%>

<%

Dim Recordset2__MMColParam

Recordset2__MMColParam = "1"

If (Request.Form("id") <>"") Then

Recordset2__MMColParam = Request.Form("id")

End If

%>

<%

Dim Recordset2

Dim Recordset2_numRows

Set Recordset2 = Server.CreateObject("ADODB.Recordset")

Recordset2.ActiveConnection = MM_conn_STRING

Recordset2.Source = "SELECT * FROM 表1 WHERE id = " + Replace(Recordset2__MMColParam, "'", "''") + " or id = 4 or id = 5"

Recordset2.CursorType = 0

Recordset2.CursorLocation = 2

Recordset2.LockType = 1

Recordset2.Open()

Recordset2_numRows = 0

%>

<%

Dim Recordset3__MMColParam

Recordset3__MMColParam = "1"

If (Request.Form("id") <>"") Then

Recordset3__MMColParam = Request.Form("id")

End If

%>

<%

Dim Recordset3

Dim Recordset3_numRows

Set Recordset3 = Server.CreateObject("ADODB.Recordset")

Recordset3.ActiveConnection = MM_conn_STRING

Recordset3.Source = "SELECT * FROM 表1 WHERE id = " + Replace(Recordset3__MMColParam, "'", "''") + " or id = 3 or id = 6"

Recordset3.CursorType = 0

Recordset3.CursorLocation = 2

Recordset3.LockType = 1

Recordset3.Open()

Recordset3_numRows = 0

%>

<%

Dim Repeat1__numRows

Dim Repeat1__index

Repeat1__numRows = -1

Repeat1__index = 0

Recordset1_numRows = Recordset1_numRows + Repeat1__numRows

%>

<%

Dim Repeat2__numRows

Dim Repeat2__index

Repeat2__numRows = -1

Repeat2__index = 0

Recordset2_numRows = Recordset2_numRows + Repeat2__numRows

%>

<%

Dim Repeat3__numRows

Dim Repeat3__index

Repeat3__numRows = -1

Repeat3__index = 0

Recordset3_numRows = Recordset3_numRows + Repeat3__numRows

%>

<html>

<body>

nume sex age socre

<p>

<%

While ((Repeat1__numRows <>0) AND (NOT Recordset1.EOF))

%>

<%=(Recordset1.Fields.Item("nume").Value)%> 

<%=(Recordset1.Fields.Item("sex").Value)%> 

<%=(Recordset1.Fields.Item("age").Value)%> 

<%=(Recordset1.Fields.Item("socre").Value)%><br>

<%

Repeat1__index=Repeat1__index+1

Repeat1__numRows=Repeat1__numRows-1

Recordset1.MoveNext()

Wend

%>

</p>

<hr>

<%

While ((Repeat2__numRows <>0) AND (NOT Recordset2.EOF))

%>

<%=(Recordset2.Fields.Item("nume").Value)%> 

<%=(Recordset2.Fields.Item("sex").Value)%> 

<%=(Recordset2.Fields.Item("age").Value)%> 

<%=(Recordset2.Fields.Item("socre").Value)%><br>

<%

Repeat2__index=Repeat2__index+1

Repeat2__numRows=Repeat2__numRows-1

Recordset2.MoveNext()

Wend

%>

<p>

<hr>

</p>

<%

While ((Repeat3__numRows <>0) AND (NOT Recordset3.EOF))

%>

<%=(Recordset3.Fields.Item("nume").Value)%> 

<%=(Recordset3.Fields.Item("sex").Value)%> 

<%=(Recordset3.Fields.Item("age").Value)%> 

<%=(Recordset3.Fields.Item("socre").Value)%><br>

<%

Repeat3__index=Repeat3__index+1

Repeat3__numRows=Repeat3__numRows-1

Recordset3.MoveNext()

Wend

%>

</body>

</html>

<%

Recordset1.Close()

Set Recordset1 = Nothing

%>

<%

Recordset2.Close()

Set Recordset2 = Nothing

%>

<%

Recordset3.Close()

Set Recordset3 = Nothing

%>

在“表1”中输入相关数据

在浏览器中测试即可。

你只是想筛选掉相同日期的数据,这个我用了临时表 #temp,你拿去改改

1,select distinct(datename(yy,time_create)+datename(mm,time_create)+datename(dd,time_create)) as date into #temp from powergroup

2,select count(*) from #temp

3,drop table #temp

两种比较简单的方法可以实现

例如: datestr 是你从数据库里查出来的日期

第一种方法: response.write(year(datestr)) ,这样输出的就是日期中的年份

第二种方法: 换个思路去考虑,有意义的年份都应该是四位数的,所以可以用截取字符串的方式去完成, response.write(left(datestr,4)) ,这样也成

希望可以帮助到你


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/69342.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-01
下一篇2023-03-01

发表评论

登录后才能评论

评论列表(0条)

    保存