adb=Request.QueryString("db")
afield=Request("txt_field")
aoperator=Request("sel_operator")
acon=Request("txt_con")
acustomcon=Request("txt_customcon")
set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="provider=sqloledb;datasource=local server;uid=scjswuser;pwd=11111111"
cn.Open
rs.ActiveConnection =cn
rs.CursorType=3
rs.Open "select * from "& adb &" where "&acustomcon
afield=Request("txt_field")
aoperator=Request("sel_operator")
acon=Request("txt_con")
acustomcon=Request("txt_customcon")
set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="provider=sqloledb;datasource=local server;uid=scjswuser;pwd=11111111"
cn.Open
rs.ActiveConnection =cn
rs.CursorType=3
rs.Open "select * from "& adb &" where "&acustomcon
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim varDate As Variant ' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn
' Open employee table.
Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockOptimistic
rstEmployees.Open "employee", cnn1, , , adCmdTable ' Assign the first employee record's hire date
' to a variable, then change the hire date.
varDate = rstEmployees!hire_date
Debug.Print "Original data"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fName & " " & _
rstEmployees!lName & " - " & rstEmployees!hire_date
rstEmployees!hire_date = #1/1/1900#
rstEmployees.Update
Debug.Print "Changed data"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fName & " " & _
rstEmployees!lName & " - " & rstEmployees!hire_date ' Requery Recordset and reset the hire date.
rstEmployees.Requery
rstEmployees!hire_date = varDate
rstEmployees.Update
Debug.Print "Data after reset"
Debug.Print " Name - Hire Date"
Debug.Print " " & rstEmployees!fName & " " & _
rstEmployees!lName & " - " & rstEmployees!hire_date rstEmployees.Close
cnn1.CloseEnd Sub
AdoCne.ConnectionTimeout = 15
AdoCne.CommandTimeout = 300
AdoCne.CursorLocation = adUseServer
sConStr = "Provider=SQLOLEDB;"
sConStr = sConStr & "Server=ServerName;"
sConStr = sConStr & "Uid=sa;"
sConStr = sConStr & "Pwd=yourpassword;"
sConStr = sConStr & "Auto Translate=false;"
sConStr = sConStr & "Database=DbName"
AdoCne.ConnectionString = sConStr
On Error GoTo err_login
AdoCne.Open另外:数据库sa最好要加密码,否则相当不安全。
你可以使用DATA控件,设置 Data 控件的数据源的名称及位置,
语法
object.DatabaseName [ = pathname ]部分 描述
object 对象表达式,其值是“应用于”列表中的对象
pathname 指示数据库文件的位置或 ODBC 数据源名称的字符串表达式对象表达式说明具体对象的表达式,可以包含对象的容器。例如,应用程序可以拥有 Application 对象,其中包含 Document 对象,而 Document 对象又包含 Text 对象字符串表达式任何其值为一连串字符的表达式。字符串表达式的元素可包含返回字符串的函数、字符串文字、字符串常数、字符串变量、字符串 Variant 或返回字符串 Variant (VarType 8) 的函数给你一个例子:
这个例子检查数据控件的 Database 属性并在 Debug 窗口中输出每个 Table 的名称。Sub PrintTableNames ()
Dim Td As TableDef
' 设置数据库文件。
Data1.DatabaseName = "BIBLIO.MDB"
Data1.Refresh ' 打开数据库。
' 读入并输出数据库中每个表的名称。
For Each Td in Data1.Database.TableDefs
Debug.Print Td.Name
Next
End Sub
On Error GoTo err1
cn.ConnectionTimeout = 100
cn.Open "Driver={SQL Server};Server=" & 服务器名 & ";Uid=" & 用户名 & ";Pwd=" & 口令 & ";Database=" & 数据库名 & ""
Exit Sub
err1:
MsgBox "连接服务器失败!请检查网络的连接是否正确"
End Sub
调用时
Dim r As new ADODB.Recordset
r.open "select *.....",cn