asp网页查询代码(asp查询表)
admin 发布:2022-12-19 19:23 169
本篇文章给大家谈谈asp网页查询代码,以及asp查询表对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
关于ASP页面查询代码
什么都没有,能显示什么?
1:要有提交form .......提交的内容/form
2:要有查询代码
求一段ASP.net网页Access查询代码
using System.Data.OleDb;
using System.Data.OracleClient;
public partial class Get : System.Web.UI.Page
{
protected void Button15_Click(object sender, EventArgs e)
{
string UserID = txtDeptId.Text.ToString().Trim();
DataTable dt = Bind(UserID);
GridView_id.DataSource = dt;
this.GridView_id.DataBind();
}
private DataTable Bind(string strWhere)
{
string connectionString = "Data Source=source;User Id=userid;Password=password;Integrated Security=no;";
String sqlStr = "select userid,username from Table where userid like '%" + strWhere + "%'";
OracleConnection myConnection = new OracleConnection(connectionString);
OracleCommand myORACCommand = myConnection.CreateCommand();
myORACCommand.CommandText = sqlStr;
myConnection.Open();
OracleDataReader myDataReader = myORACCommand.ExecuteReader();
Object mm = null;
DataTable dt = new DataTable("datetable");
int intFieldCount = myDataReader.FieldCount;
for (int intCounter = 0; intCounter = intFieldCount - 1; intCounter++)
{
dt.Columns.Add(myDataReader.GetName(intCounter), myDataReader.GetFieldType(intCounter));
}
dt.BeginLoadData();
object[] objValues = new object[intFieldCount ];
while (myDataReader.Read())
{
myDataReader.GetValues(objValues);
dt.LoadDataRow(objValues, true);
}
myDataReader.Close();
myConnection.Close();
return dt;
}
}
asp中查询按钮代码
查询页面 search.htm
form id="form1" name="form1" method="post" action="search.asp"
table width="400" border="1"
tr
td width="100"输入查询内容/td
tdlabel
input type="text" name="textbox1" id="textbox1" /
/label/td
/tr
tr
td colspan="2" align="center"label
input type="submit" name="button" id="button" value="查询" /
/label/td
/tr
/table
/form
查询程序页面 search.asp
%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title无标题文档/title
/head
body
%
'前提条件 添加连接数据库代码
if trim(request.Form("textbox1"))"" then
sql="select * from 表名 where 字段名 like '%"trim(request.Form("textbox1"))"%' order by id desc"'自己用其他方式排序也可以
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.Write("没有记录")
else
do while not rs.eof
response.Write("输入自己想要的记录br/")'这里就是你充分发挥你的想象力 用什么方式输出查询的结果了
rs.movenext
loop
rs.close
set rs=nothing
else
response.Write("没有输入查询条件")
end if
%
/body
/html
asp查询代码
1. 首先要创建数据库连接,代码如下:
%
dim conn,db
dim connstr
db="db/accessdbname.mdb" '数据库文件位置
on error resume next
connstr="DBQ="+server.mappath(""db"")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
end if
sub CloseConn()
conn.close
set conn=nothing
end sub
%
2. 读取数据
%
set rs=server.createobject("adodb.recordset")
sql="select * from tushuxitong where id='3'"
rs.open sql,conn,1,1
%
3. 输出数据
%
response.write rs("zhongwen") ' 输出中文
response.write rs("yingwen") ' 输出英文
response.write rs("riwen") ' 输出日文
%
ASP查询代码
1、要查询的数据库名称:data.mdb
数据库中表为:data
数据库表data的字段有:title、about
由于无数据添加页面,所以在数据库各字段中应添加数据,方便查询演示。
2、数据库打开文件conn.asp:
%
Server.scriptTimeout="10"
connstr="DBQ="+server.mappath("data.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=Server.CreateObject("ADODB.connection")
conn.open connstr
%
3、查询文件search.asp:
!--#include file="conn.asp"--
form name="frm_Search" method="get" action="Search.asp"
请输入关键字:
input type="text" name="key" size="10"
input type="submit" value="搜索"
/form
%
Dim S_Key,RST,StrSQL
S_Key = Trim(Request("key")) '得到搜索关键字的值
If S_Key "" then
Set RST=Server.CreateObject("ADODB.RecordSet")
StrSQL=AutoKey(S_Key) '此处使用自定义函数 AutoKey(),该函数为实现智能搜索的核心
RST.Open StrSQL,conn,3,2 '得到搜索后的记录
If RST.BOF And RST.EOF Then
%
font color="#FF0000"Sorry,未找到任何结果!/font
%
Else
%
搜索名称为“font color="#FF0000"%= S_Key %/font”的项,共找到 font color="#FF0000"%= RST.RecordCount %/font 项:p
%
While Not RST.EOF
%
!-- 此处可设为你所需要的链接目标 --
font style="font: 12pt 宋体"a href="show.asp?ID=%= RST("ID") %" target="_blank"%= RST("title") %/a/fontbr
!-- 显示部分详细内容 --
font style="font: 9pt 宋体"%= Left(RST("about"),150) %/fontp
%
RST.MoveNext
Wend
RST.Close
Set RST=Nothing
End If
End If
% %
Function AutoKey(strKey)
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey
'检测字符串的合法性,若不合法则转到出错页。出错页你可以根据需要进行设定。
if InStr(strKey,"=")0 or InStr(strKey,"`")0 or InStr(strKey,"'")0 or InStr(strKey," ")0 or InStr(strKey," ")0 or InStr(strKey,"'")0 or InStr(strKey,chr(34))0 or InStr(strKey,"\")0 or InStr(strKey,",")0 or InStr(strKey,"")0 or InStr(strKey,"")0 then
Response.Redirect "error.htm"
End If
lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 '若为空串,转到出错页
Response.Redirect "error.htm"
Case 1 '若长度为1,则不设任何值
strNew1=""
strNew2=""
Case Else '若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件
For i=1 To lngLenKey-(lngSubKey-1)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 " or title like '%" strSubKey "%'"
strNew2=strNew2 " or about like '%" strSubKey "%'"
Next
End Select
'得到完整的SQL语句
AutoKey="Select * from data where title like '%" strKey "%' or about like '%" strKey "%'" strNew1 strNew2
End Function
%
%
conn.Close
Set conn=Nothing
%
4、查询后显示页面show.asp:
!--#include file="conn.asp"--
%id=request.querystring("id")%
%set show=conn.execute("select*from data where id="id"")%
hr size="1"
table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="180"
tr
td width="50%" height="22"b标题:/b%=show("title")%/td
td width="50%" height="22"b关于:/b%=show("about")%/td
/tr
/table
%set show=nothing%
5、检索出错文件error.htm
html
head
title
出错啦!
/title
/head
body
center对不起,您要检索的信息字符串不合法则!br请a href="javascript:history.back(1)"返回/a重新检索!/center
/body
/html
说明:将以上文件和数据库放在同一目录下.也可以将数据库文件data.mdb放在其他文件夹,但注意修改conn.asp相应的数据库地址。
asp网页查询代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于asp查询表、asp网页查询代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-01html天气预报免费代码(天气预报的代码)[20240501更新]
- 05-01图片预加载代码(图片预加载原理)[20240501更新]
- 05-01登录器代码怎么写(登录器代码怎么写的)[20240501更新]
- 05-01源代码阅读器(开源代码阅读工具)[20240501更新]
- 05-01vb连连看代码(vb连等会出现什么情况)[20240501更新]
- 05-01eclipse五子棋代码思路(eclipse五子棋小游戏代码)[20240501更新]
- 05-01在线域名查询网站,域名查询2021
- 05-01栏目框代码(菜单栏代码)[20240501更新]
- 05-01包含html的字体样式代码的词条[20240501更新]
- 05-01导航栏滑动代码(页面导航栏代码)[20240501更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接