gpt4 book ai didi

sql-server - 如何从 Visual Basic 6 连接到 Sql Server 2008 数据库?

转载 作者:行者123 更新时间:2023-12-02 20:24:17 25 4
gpt4 key购买 nike

正确的连接字符串是什么?从 Visual Basic 6 连接到 Sql Server 2008 数据库有哪些要求?

最佳答案

' Initialize variables.
Dim cn As New ADODB.Connection
Dim provStr As String

' Specify the OLE DB provider.
cn.Provider = "sqloledb"

' Specify connection string on Open method.
ProvStr = "Server=MyServer;Database=northwind;Trusted_Connection=yes"
cn.Open provStr

仅用于说明( Ref 。):

Set rsOrders = New Recordset
rsOrders.Open "Select * from orders", cn
Do While Not rsOrders.EOF
'
' If the order matches some custom business logic then get the details for
' that order, without opening a new connection.
'
If SomeBusinessLogic(rsOrders("CustomerID")) Then
Dim rsDetails As Recordset
Set rsDetails = New Recordset
'
' Open a new recordset using the same connection. Normally it's not
' possible to have two recordsets simultaniously using the same
' connection, but MARS makes this possible
'
rsDetails.Open "Select sum(quantity * unitprice) as total " & _
"from [order details] " & _
"where OrderID=" & rsOrders("OrderID"), _
cn
grandTotal = grandTotal + rsDetails("total")
End If
rsOrders.MoveNext
Loop

lblTotalOrders = grandTotal

关于sql-server - 如何从 Visual Basic 6 连接到 Sql Server 2008 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7696083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com