1>asp下面一個普通的access/sql連接
<%
Set CountConn = Server.CreateObject("ADODB.Connection")
CountFile = Server.MapPath("pic.mdb")
CountConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("pic.mdb")
'Const strConnectString = "Provider=sqloledb;User ID=pubsLogin; pwd=pubsPassword; Data Source=YourServerName; Initial Catalog=pubs"
Set rs = Server.CreateObject("ADODB.RecordSET")
rs.Open "Select * from count where id = '" & id & "'",CountConn,1,1
If not rs.EOF Then
count = rs("count")
End If
rs.Close
%>
2>asp下面一個普通的mysql連接
寫法和上面的一樣,但連接字串不同
'connect to MySQL server using MySQL ODBC 3.51 Driver(使用MySQL ODBC 3.51驱动程序连接到MySQL服务器)
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};"_
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
' Open the Connection object to either the IOM or SAS/SHARE provider.
cmd.ActiveConnection = cn
' Create a new table.
cmd.CommandText = "create table sasuser.newtable ( i num, name char(40), age num );"
cmd.Execute
' Insert values into the new table.
cmd.CommandText = "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
cmd.Execute
' Open a Recordset object on the new table.
cmd.CommandText = "select * from sasuser.newtable"
Set rs = cmd.Execute()
' Do something with the recordset.
MsgBox rs.GetString
rs.Close
cn.Close

Sub Main()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the Connection Object to either the IOM or SAS/SHARE provider.
' Create a new table.
cn.Execute "create table sasuser.newtable ( i num, name char(40), age num );"
' Insert values into the new table.
cn.Execute "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
' Open a Recordset object on the new table.
Set rs = cn.Execute("select * from sasuser.newtable")
' Do something with the Recordset.
MsgBox rs.GetString
rs.Close
cn.Close

End Sub
<%
Set CountConn = Server.CreateObject("ADODB.Connection")
CountFile = Server.MapPath("pic.mdb")
CountConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("pic.mdb")
'Const strConnectString = "Provider=sqloledb;User ID=pubsLogin; pwd=pubsPassword; Data Source=YourServerName; Initial Catalog=pubs"
Set rs = Server.CreateObject("ADODB.RecordSET")
rs.Open "Select * from count where id = '" & id & "'",CountConn,1,1
If not rs.EOF Then
count = rs("count")
End If
rs.Close
%>
2>asp下面一個普通的mysql連接
寫法和上面的一樣,但連接字串不同
'connect to MySQL server using MySQL ODBC 3.51 Driver(使用MySQL ODBC 3.51驱动程序连接到MySQL服务器)
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};"_
& "SERVER=localhost;"_
& " DATABASE=test;"_
& "UID=venu;PWD=venu; OPTION=3"
3>Example
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
' Open the Connection object to either the IOM or SAS/SHARE provider.
cmd.ActiveConnection = cn
' Create a new table.
cmd.CommandText = "create table sasuser.newtable ( i num, name char(40), age num );"
cmd.Execute
' Insert values into the new table.
cmd.CommandText = "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
cmd.Execute
' Open a Recordset object on the new table.
cmd.CommandText = "select * from sasuser.newtable"
Set rs = cmd.Execute()
' Do something with the recordset.
MsgBox rs.GetString
rs.Close
cn.Close

Sub Main()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the Connection Object to either the IOM or SAS/SHARE provider.
' Create a new table.
cn.Execute "create table sasuser.newtable ( i num, name char(40), age num );"
' Insert values into the new table.
cn.Execute "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
' Open a Recordset object on the new table.
Set rs = cn.Execute("select * from sasuser.newtable")
' Do something with the Recordset.
MsgBox rs.GetString
rs.Close
cn.Close
End Sub
浙公网安备 33010602011771号