Database connection

zhaozj2021-02-16  59

ASP and SQL Server database connection <% 'connection database -------------------------- set conn = server.createObject ("adoDB. ConNSTR = "proviDER = SQLOLEDB; DATA SOURCE = 127.0.0.1; UID = SA; PWD = SA; Database = Web" "Open Database ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------Conn.open connStr 'write data inquiry statement ---------------------- SET RS = conn.execute ("SELECT * ASP where ID> 2") 'Output Query Results ------------------------ DO Until RS .EOF response.write RS ("ID") & "
" Response.write RS ("Name") & "
" rs.movenextLoop%> ************ *********************************************************************************************************************** *********** <% DIM Conn Dim 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 conn.execute (" SELECT) * from login_info where id> 1 ") Do Until Rs.eof Response.write RS (" ID ") &"
"Response.write RS ("Username") & "
" Response.write RS ("Password") & "
" rs.movenextLoop%>

*********************************************************** *********************************************************** ****** <% set = conn.execute ("Select * from login_info where id> 2") 'set = 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") & "
"Response.write RS (" UserName ") &"
"Response.write RS (" Password ") &"
"rs.movenextloop%> ************ *********************************************************** *********************************************************** ****

Methods of connecting other databases (* .dbf, *. Txt, excel, foxpro, etc.) ---- Collection 2002-10-30 18:41:05 Views: 145 'link DBF file <%' Established Connection Object SET CONN = Server.createObject ("adodb.connection") driver = "driver = {Microsoft Visual FoxPro Driver};" SourceType = "SourceType = DBF;" DBPATH = "SourceDb =" & Server.mAppath ("DBF")

'Call Open method Connection Database Conn.open Driver & SourceType & Dbpath

SET RS = Server.createObject ("AdoDb.Recordset") 'Opens the data source, the parameter 2 is the Connection object Rs.Open "Select * from sample", CONN, 2, 2%> "Connect FoxPro file <%' Established Connection Object Set conn = Server.CreateObject ( "ADODB.Connection") Driver = "Driver = {Microsoft Visual FoxPro Driver};" SourceType = "SourceType = DBC;" DBPath = "SourceDB =" & Server.MapPath ( "Dbf / Sample .dbc ")

'Call the Open method Connection Database Conn.open Driver & SourceType & dbPathSet RS = Server.createObject ("AdoDb.Recordset")' Opens the data source, the parameter 2 is the connection  object rs.open "Select * from sample", conn, 2, 2%>

'Connecting Excel File <%' Establishing Connection Object SET CONN = Server.createObject ("AdoDb.Connection") Driver = "Driver = {Microsoft Excel Driver (* .xls)};" dbpath = "dbq =" & Server.MAppath ("Sample.xls")

'Call OPEN Method Connection Database Conn.open Driver & Dbpath

SET RS = Server.createObject ("AdoDb.Recordset") 'Opens the data source, the parameter 2 is the connection object rs.open "Select * from [transcripts $], CONN, 2, 2%>

'Link TXT file <%'  Establish Connection object set conn = server.createObject ("AdoDb.connection") driver = "driver = {Microsoft text driver (* .txt; * .csv)};" dbpath = "dbq = "& Server.MAppath (" text ")

'Call OPEN Method Connection Database Conn.open Driver & Dbpath

SET RS = Server.createObject ("AdoDB.Recordset") 'Opens the data source, the parameter 2 is the connection object Rs.Open "Select * from sample.txt", conn, 2, 2%>

SELECT syntax: (basics)

*********************************************************** *********************************************************** ******************* SELECT [DISTINCT] (Column [{, Column}] | * from Table [{, Table}] [Order By Column [ASC] | [Desc] | [DESC}]] Where Predicate [{Logical-Connector Predicate}]; ---------------------------------------------------------------------------------------------------- ------------------------------

INSERT syntax:

INSERT INTO TABLE [(Column {, column})] Values ​​(ColumnValue [{, ColumnValue}]); --------------------------- ---------------------------

Update syntax:

Update TableSet Column = Value [{, Column = Value}] [WHERE Predicate [{Logical-Connector Predicate}]]; ------------------------ ------------------------------

Delete syntax:

Delete from table [where predicate]]; -------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------

转载请注明原文地址:https://www.9cbs.com/read-22944.html

New Post(0)