asp與資料庫的串連

來源:互聯網
上載者:User

asp與sql server 資料庫的串連
<%
'串連資料庫————————————————————————————
set conn=server.createobject("adodb.connection")
Connstr="Provider=SQLOLEDB;Data Source=127.0.0.1;UID=sa;PWD=sa;DataBase=web"
'開啟資料庫——————————————————————————————————
conn.open connstr 
'寫資料查詢語句————————————————————————
set rs=conn.execute("select * from asp where id>2")
'輸出查詢結果——————————————————————————
do until rs.eof
   response.write rs("id")&"<br>"
   response.write rs("name")&"<br>"
   rs.movenext
loop
%>
************************************
asp與access 資料庫的串連
********************************
<% dim conn  
   dim connstr
   on error resume next
   connstr="DBQ="+server.mappath("login.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
   set conn=server.createobject("ADODB.CONNECTION")
   if err then
      err.clear
   else
        conn.open connstr
        if err then
           err.clear
        end if
   end if
set rs=conn.execute("select * from login_info where id>1")
do until rs.eof
  response.write rs("id")&"<br>"
  response.write rs("username")&"<br>"
  response.write rs("password")&"<br>"
  rs.Movenext
loop %>

*****************************************************
*****************************************************
<!--#include file="conn.asp"-->
<%
set rs=conn.execute("select * from login_info where id>2")
'set rs=server.createobject("adodb.recordset")
'sql="select * from login_info where id > ='1' "
'rs.open sql,conn,1,1
do until rs.eof
  response.write rs("id")&"<br>"
  response.write rs("username")&"<br>"
  response.write rs("password")&"<br>"
  rs.Movenext
loop
%>

**********************************************************
***********************************************************

連結其他資料庫的方法(*.dbf,*.txt,excel,foxpro等)    ----收藏
2002-10-30 18:41:05   瀏覽次數:145 
 
'連結dbf檔案
<%
'  建立Connection  對象
Set  conn  =  Server.CreateObject("ADODB.Connection")
Driver  =  "Driver={Microsoft  Visual  FoxPro  Driver};"
SourceType  =  "SourceType=DBF;"
DBPath  =  "SourceDB="  &  Server.MapPath(  "Dbf"  )

'  調用Open  方法串連資料庫
conn.Open  Driver  &  SourceType  &  DBPath

Set  rs  =  Server.CreateObject("ADODB.Recordset")
'  開啟資料來源,參數二為Connection對象
rs.Open  "Select  *  From  sample",  conn,  2,  2
%>
'連結foxpro檔案
<%
'  建立Connection  對象
Set  conn  =  Server.CreateObject("ADODB.Connection")
Driver  =  "Driver={Microsoft  Visual  FoxPro  Driver};"
SourceType  =  "SourceType=DBC;"
DBPath  =  "SourceDB="  &  Server.MapPath(  "Dbf/Sample.dbc"  )

'  調用Open  方法串連資料庫
conn.Open  Driver  &  SourceType  &  DBPath

Set  rs  =  Server.CreateObject("ADODB.Recordset")
'  開啟資料來源,參數二為Connection對象
rs.Open  "Select  *  From  sample",  conn,  2,  2
%>

'連結excel檔案
<%
'  建立Connection對象
Set  conn  =  Server.CreateObject("ADODB.Connection")
Driver  =  "Driver={Microsoft  Excel  Driver  (*.xls)};"
DBPath  =  "DBQ="  &  Server.MapPath(  "Sample.xls"  )

'  調用Open  方法串連資料庫
conn.Open  Driver  &  DBPath

Set  rs  =  Server.CreateObject("ADODB.Recordset")
'  開啟資料來源,參數二為Connection對象
rs.Open  "Select  *  From  [成績單$]",  conn,  2,  2
%>

'連結txt檔案
<%
'  建立Connection  對象
Set  conn  =  Server.CreateObject("ADODB.Connection")
Driver  =  "Driver={Microsoft  Text  Driver  (*.txt;  *.csv)};"
DBPath  =  "DBQ="  &  Server.MapPath(  "Text"  )

'  調用Open  方法串連資料庫
conn.Open  Driver  &  DBPath

Set  rs  =  Server.CreateObject("ADODB.Recordset")
'  開啟資料來源,參數二為Connection對象
rs.Open  "Select  *  From  sample.txt",  conn,  2,  2
%>

 

 

SELECT文法:(基本)

 

*************************************************************
**********************************************************
SELECT [DISTINCT]
(column [{, column } ] )| *
FROM table [ { , table} ]
[ORDER BY column [ASC] | [DESC
[{ , column [ASC] | [DESC } ] ]
WHERE predicate [ { logical-connector predicate } ];
------------------------------------------------------

INSERT文法:

INSERT INTO table
[(column { ,column})]
VALUES
(columnvalue [{,columnvalue}]);
------------------------------------------------------

UPDATE文法:

UPDATE table
SET column = value [{, column = value}]
[ WHERE predicate [ { logical-connector predicate}]];
------------------------------------------------------

DELETE文法:

DELETE FROM table
[WHERE predicate [ { logical-connector predicate} ] ];
------------------------------------------------------
blueice2002 2003-03整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.