【发布时间】:2016-11-03 22:21:36
【问题描述】:
我尝试使用以下代码从 sql 中取回数据。连接很好,一切正常,但是,我想将以下代码的内容存储在访问表中。 请问有人可以帮忙吗?
Public PERSONALDBCONT As Object, _
SQLSTR As String, SQLSTR1 As String, _
SQLSTR2 As String, SQLSTR3 As String, _
RecCount As String, DB As String
Function CONNECT_TO_DB()
Set PERSONALDBCONT = CreateObject("ADODB.connection")
Dim SCONN As String
SCONN = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & tempdb & ";Data Source=WBACUKSQLPD001;" & _
"Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=WBAC173427;Use Encryption for Data=False;Tag with column collation when possible=False"
PERSONALDBCONT.Open SCONN
End Function
Function CLOSE_CONNECTION_TO_SQL()
On Error Resume Next
PERSONALDBCONT.Close
Set PERSONALDBCONT = Nothing
On Error GoTo 0
End Function
Sub SQL_()
Dim rs As Object
Dim iCols As Integer
Set rs = CreateObject("ADODB.Recordset")
On Error GoTo ERR
CONNECT_TO_DB
Dim SQLSTR As String
SQLSTR = "Select top 1 * from sys.objects"
rs.Open SQLSTR, PERSONALDBCONT
Exit Sub
ERR:
CLOSE_CONNECTION_TO_SQL
MsgBox "There was an error at " & Stage & "." & vbNewLine & "Please see the instructions and investigate"
If Application.Visible = False Then Application.Visible = True
End
End Sub
【问题讨论】:
-
能不能链接到access DB,然后简单的INSERTINTO MAKE TABLE等
-
嗨@Nathan_Sav,我不确定你所说的链接是什么意思。
-
google 将 SQL 服务器表链接到 Access。
-
啊,对不起。我以为你的意思类似于excel的连接。这没有用,因为我需要运行查询并且我没有对 sql 的写入权限,因此无法创建 proc,它不像从表中选择那么简单。
-
只在访问中使用链接表,或者获得访问权限来完成它