50分!!!!!!怎样用ado连sql server7.0,加急!急!

jxh_jxh 2000-08-28 04:23:00
我想在程序中用语句把ado和sql70连起来,怎么办?
我已经创建了odbc数据源,user id=sa,password="",请问语句应该怎么样?
我已经忙了好几天了,快帮帮我。最好把完整语句写出来,再一次谢谢了
我的信箱是jxh_jxh@371.net
...全文
142 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guest 2000-08-28
  • 打赏
  • 举报
回复
前面写错了应该是

public cn as new adodb.Connection


调用时
Dim r As new ADODB.Recordset
r.open "select *.....",cn

guest 2000-08-28
  • 打赏
  • 举报
回复
提供一段我用的模块

public cn as new adodb.re...

Sub ConSQL(服务器名 As String, 用户名 As String, 口令 As String, 数据库名 As String)
On Error GoTo err1
cn.ConnectionTimeout = 100
cn.Open "Driver={SQL Server};Server=" & 服务器名 & ";Uid=" & 用户名 & ";Pwd=" & 口令 & ";Database=" & 数据库名 & ""
Exit Sub
err1:
MsgBox "连接服务器失败!请检查网络的连接是否正确"
End Sub
0xFFCD 2000-08-28
  • 打赏
  • 举报
回复
你可以直接使用该数据库。
你可以使用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






bing71 2000-08-28
  • 打赏
  • 举报
回复
Set AdoCne = New ADODB.Connection
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最好要加密码,否则相当不安全。
huntout 2000-08-28
  • 打赏
  • 举报
回复
給你個例程參考一下!︰)

Public Sub OpenX()

Dim cnn1 As ADODB.Connection
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.Close

End Sub

jhb 2000-08-28
  • 打赏
  • 举报
回复
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


7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧