救命呀。ado连接的sql server数据库,我想实现查询的功能,完整步骤------在先等待

wangyansurmount 2003-10-21 09:34:15
ado连接的sql server数据库,我想实现查询的功能,代码怎么写呀,
谢谢各位大虾了

...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yourbj 2003-10-21
  • 打赏
  • 举报
回复
也可以自己定义Connection

Dim cnn1 As ADODB.Connection
Dim cnn2 As ADODB.Connection
Dim cnn3 As ADODB.Connection
Dim cnn4 As ADODB.Connection

' 不使用数据源名 (DSN) 打开连接。
Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "driver={SQL Server};" & _
"server=bigsmile;uid=sa;pwd=pwd;database=pubs"
cnn1.ConnectionTimeout = 30
cnn1.Open

' 使用 DSN 和 ODBC 标记打开连接。
Set cnn2 = New ADODB.Connection
cnn2.ConnectionString = "DSN=Pubs;UID=sa;PWD=pwd;"
cnn2.Open

' 使用 DSN 和 OLE DB 标记打开连接。
Set cnn3 = New ADODB.Connection
cnn3.ConnectionString = "Data Source=Pubs;User ID=sa;Password=pwd;"
cnn3.Open

' 使用 DSN 和单个参数而非连接字符串打开连接。
Set cnn4 = New ADODB.Connection
cnn4.Open "Pubs", "sa", "pwd"

' 显示连接的状态。
MsgBox "cnn1 state: " & GetState(cnn1.State) & vbCr & _
"cnn2 state: " & GetState(cnn2.State) & vbCr & _
"cnn3 state: " & GetState(cnn3.State) & vbCr & _
"cnn4 state: " & GetState(cnn4.State)

cnn4.Close
cnn3.Close
cnn2.Close
cnn1.Close
yourbj 2003-10-21
  • 打赏
  • 举报
回复
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DE.cnnTest.Open '打开连接,我的连接是设计器里DE(dataenvironment)的cnnTest(connection)
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "SELECT GetDate()", DE.cnnTest
llyyll 2003-10-21
  • 打赏
  • 举报
回复
请你讲清楚,是要达到什么目的。
wangyansurmount 2003-10-21
  • 打赏
  • 举报
回复
不对的代码,乱写,写个对的可以吗,我急得要命呀
射天狼 2003-10-21
  • 打赏
  • 举报
回复
Dim rs As New ADODB.Recordset

rs.Open "select * from table where name = '" & text1.Text & "'", cn, adOpenForwardOnly, adLockReadOnly

7,762

社区成员

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

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