當前位置:首頁 » 操作系統 » asp資料庫查詢代碼

asp資料庫查詢代碼

發布時間: 2022-12-06 08:50:12

① asp連接sql資料庫的增刪改查完整代碼

<%
dimconn,db
dimconnstr
db="db.mdb"'access資料庫文件路徑
connstr="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="&server.MapPath(""&db&"")&";PersistSecurityInfo=False;"
setconn=server.createobject("ADODB.CONNECTION")

'連接資料庫
conn.openconnstr'opendatebase

'資料庫結構
'文件名db.mdb
'表名admin
'欄位id,自動編號
'欄位username,文本
'欄位userpass,文本

'增
setRs=server.createobject("adodb.recordset")
Sql="select*fromadmin"
Rs.openSql,conn,1,3
Rs.addnew
Rs("username")="用戶名"
Rs("userpass")="用戶密碼"
Rs.update
Rs.close
setRs=nothing
response.Write"<scriptlanguage='javascript'>alert('管理員增加成功!');'</script>"

'刪
s_id=1'假設有個用戶數據的id為1
Sql="delete*fromadminwhereid="&s_id&""
setRs=server.CreateObject("ADODB.recordset")
rs.openSql,conn,1,3
response.Write("<script>alert('帳號刪除成功!');</script>")
rs.close
setRs=nothing

'改
s_id=1'假設有個用戶數據的id為1
setRs=server.createobject("adodb.recordset")
Sql="select*fromadminwhereid="&s_id&""
Rs.openSql,conn,1,3
ifRs.eofandRs.bofthen
Rs.close
setRs=nothing
response.Write("<scriptlanguage='javascript'>alert('此用戶不存在!');history.back();</script>")
else
Rs("Password")="新密碼"
Rs.update
Rs.close
setRs=nothing
response.Write("<scriptlanguage='javascript'>alert('密碼修改成功!');</script>")
EndIf

'查單個
s_username="admin"'假設有個用戶名為admin的用戶數據
setRs=server.createobject("adodb.recordset")
Sql="select*fromadminwhereusername='"&s_username&"'"
Rs.openSql,conn,1,3
ifRs.eofandRs.bofthen
Rs.close
setRs=nothing
response.Write("<scriptlanguage='javascript'>alert('此用戶不存在!');history.back();</script>")
else
s_name=Rs("username")
s_pass=Rs("userpass")
Rs.close
setRs=nothing

'輸出查詢到的信息
response.Write("<scriptlanguage='javascript'>alert('你查詢的用戶名"&s_name&"的密碼為:"&s_pass&"');</script>")
EndIf

'查列表
setRs=server.CreateObject("Adodb.recordset")
sql="select*fromadminorderbyiddesc"
Rs.opensql,conn,1,1
ifnotRs.eofthen

'循環輸出查詢到的信息
dowhilenotRs.eof
response.Write"id:"&Rs("id")&",用戶名:"&Rs("username")&",密碼:"&Rs("userpass")&"<br/>"
Rs.movenext
loop

endif
Rs.close
setRs=nothing


'使用完資料庫後要關閉連接資源
conn.close
setconn=nothing
%>

② 求助asp查詢asp資料庫

一、找著有資料庫連接文件,很多人喜歡用conn.asp這樣的文件名作為資料庫連接文件,如果找到有conn.asp文件可直接打開看看,如果沒有可以整站搜索「ADODB.CONNECTION」,一般就能找到資料庫連接文件了。
二、打開資料庫連接文件看資料庫名和密碼,給你舉三個例吧:
例1:某網站的conn.asp有這樣的代碼:
db="db/jhq##sdfsad#.asp" '資料庫文件位置
on error resume next
connstr="DBQ=" & Server.MapPath(db) & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
那麼他的資料庫是ACCESS資料庫,在這個db文件夾下的jhq##sdfsad#.asp就是資料庫,密碼是空。

例2:某網站的config.asp有這樣的代碼:
set conn=server.createobject("ADODB.CONNECTION")
conn.Connectionstring = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;Jet OLEDB:Database password=548tj47f;DATA SOURCE=" & Server.MapPath("/App_Data/# %otc4468fde% #.mdb")
那麼他的是ACCESS資料庫,App_Data文件夾下的# %otc4468fde% #.mdb就是,密碼是548tj47f

例3:某網站的config.asp有這樣的代碼:
set conn=server.createobject("ADODB.CONNECTION")
conn.Connectionstring = "provider=sqloledb;data source=127.0.0.1;User ID=aa6378643;pwd=D5Lo9JHUT;Initial Catalog=aa6378643"
那麼他的資料庫是mssql資料庫,資料庫名是aa6378643,用戶名是aa6378643,密碼是D5Lo9JHUT,IP跟網站IP一樣。

③ 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資料庫查詢代碼

Form提交的數據一般用傳值post方式傳送。你用的是傳址get。

接收FORM數據的方式是:
type1=request.form("type1")
type2=request.form("type2")

還有count=1你准備幹啥?

⑤ 求ASP查詢資料庫代碼

首先鏈接資料庫:
class DBHelper
{
public static SqlConnection connection = new SqlConnection("DataSource=.\\db2005;Initial Catalog=mealo;Integrated Security=True");
}
然後編寫增、刪、改、查等語句對資料庫的數據進行操作、查詢。
如查詢桌台全部信息:
public DataTable SelectAll()
{
string sql = "select * from TBll";
SqlDataAdapter thisAdapter = new SqlDataAdapter(sql, DBHelper.connection);
//DBHelper.connection.Open();
DataSet TableDataSet = new DataSet();
thisAdapter.Fill(TableDataSet, "桌台表");
DataTable Table = TableDataSet.Tables["桌台表"];
return Table;
}

這個是你的問題:《""我想在查詢頁面中輸入任意一個欄位值.怎麼在查詢結果頁面中顯示符合要求的一項數據""
》————其實很簡單
只要寫一個SQL語句就可以解決了
如:string sql = "select * from 表名 where 條件 like %任意字% ";
非常之簡單, 寫了這么多希望採納啊~!! 有不懂的還可以問我.......

⑥ 求助asp查詢資料庫的代碼

'定義鏈接
setconn=Server.CreateObject("ADODB.Connection")
conn.open"provider=sqloledb.1;PersistSecurityInfo=false;datasource=資料庫地址;UserID=用戶名;pwd=用戶密碼;InitialCatalog=資料庫名字"
'定義表
Setds=Server.CreateObject("ADODB.Recordset")
'查詢語句
sql="select*fromTable1"
'查詢
ds.opensql,conn,1,1
'循環綁定
DoWhileNotds.Eof
Response.Write"<li><span>"&ds("date")&"</span><span>"&ds("id")&"</span></li>"
ds.Movenext
Loop
'關閉對象
ds.CLose
Setds=Nothing
conn.CLose
Setconn=Nothing

⑦ asp查詢代碼怎麼寫

sql="select * from room where rnum='"&rnum"' 這句錯了

應該是sql="select * from room where rnum="'&rnum&'""

⑧ asp怎樣查詢資料庫

首先創建SqlConnection對象連接資料庫,然後定義查詢字元串,最後對GridView控制項進行數據綁定。
示例:
下面通過一個示例介紹在ASP.NET 2.0應用程序中如何查詢資料庫中記錄。
新建一個網站,默認主頁為Default.aspx,在Default.aspx頁面上分別添加一個TextBox控制項、一個Button控制項和一個GridView控制項,並把Button控制項的Text屬性值設為「查詢」。該頁在實現時,首先編寫一個GridView控制項數據綁定方法bind(該方法請參見5.3.2中bind方法),並在Page_Load事件中調用該方法顯示資料庫中記錄,具體代碼如下。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bind();
}
}
然後在【查詢】按鈕Click事件下編寫實現資料庫查詢操作的代碼,具體代碼如下。
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
string str = "select * from Region where RegionID='" + TextBox1.Text.Trim() + "'";
sqlconn = new SqlConnection(sqlstr);
sqlconn.Open();
SqlCommand sqlcom = new SqlCommand(str,sqlconn);
int result = Convert.ToInt32(sqlcom.ExecuteScalar());
if (result > 0)
{
SqlDataAdapter myda = new SqlDataAdapter(str, sqlconn);
DataSet myds = new DataSet();
myda.Fill(myds);
GridView1.DataSource = myds;
GridView1.DataBind();
sqlconn.Close();
}
else
Response.Write("<script>alert('沒有相關記錄')</script>");
}
else
this.bind();
}

⑨ 急求!asp怎麼寫查詢資料庫代碼

運行asp文件需要iis支持的。如果直接通過本地地址是打不開的,
安裝IIS後在信息伺服器上設置你的網站主目錄文件夾,然後通過在IE中輸入:http://localhost/sele.htm打開文件後點擊提交按鈕才能運行asp文件。
安裝方法很簡單,插入系統光碟,點擊系統可選的組件,將IIS信息伺服器選中,安裝即可。安裝成功後在IE中輸入http://localhost/ 如果出現兩個頁面,表示安裝成功了!
然後在控制面板,管理工具中即可找到信息伺服器

⑩ asp.net的資料庫查詢語句

例子:
//建立資料庫連接對象sc
SqlConnection sc = new SqlConnection();
//資料庫連接字元串
sc.ConnectionString = "server=.;database=wangjun;uid=sa;pwd=sqlserver";
//打開資料庫
sc.Open();
Console.WriteLine("已經連接");
//資料庫命令對象字元串
string sql = "select rtrim(學號),rtrim(姓名),rtrim(性別),rtrim(總分),rtrim(address),rtrim(所屬院系) from student";
//新建資料庫命令對象
SqlCommand cmd = new SqlCommand(sql,sc);
//新建數據集對象reader 並得到命令對象讀取的結果集
SqlDataReader reader = cmd.ExecuteReader();
//使用循環輸出數據集中的數據
while (reader.Read())
{
Console.WriteLine("{0} | {1} | {2}| {3} | {4} | {5}",reader[0],reader[1],reader[2],reader[3],reader[4],reader[5]);
}
還可以用SqlDataAdapter 然後填充到dataset裡面
然後對dataset操作即可

熱點內容
存儲念第幾音 發布:2024-04-26 20:33:35 瀏覽:250
衡陽dns的伺服器地址是多少 發布:2024-04-26 20:32:26 瀏覽:269
我的世界空島伺服器青金石 發布:2024-04-26 20:18:03 瀏覽:650
微信小程序演算法 發布:2024-04-26 20:03:36 瀏覽:975
易語言模板不能靜態編譯 發布:2024-04-26 19:59:02 瀏覽:353
sql注釋語句 發布:2024-04-26 19:58:48 瀏覽:654
sql存儲過程out 發布:2024-04-26 19:33:15 瀏覽:415
struts2訪問方法 發布:2024-04-26 19:11:36 瀏覽:259
外文翻譯android 發布:2024-04-26 19:03:30 瀏覽:92
土金木配置怎麼樣 發布:2024-04-26 18:52:50 瀏覽:611