|
本帖最后由 竹笛 于 2013-6-25 15:56 编辑
将SQL的数据库保存到Access表,先链接到SQL服务器,然后写到本地的Access本里
下面是一个例子,我把示例在最下面
Dim rst As ADODB.Recordset
Dim strConnect As String
Dim strSQL As String
' 使用Microsoft Data Shaping Service for OLE DB provider连接到sql server.
strConnect = "Provider=MSDataShape;Data Provider=SQLOLEDB;" _
& "Integrated Security=SSPI;Data Source=len1060;" _
& "Initial Catalog=Northwind;user id=sa;password="
'也可以使用下面的连接字符串
'strConnect = "Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=len1060;User ID=sa;Password=;Initial Catalog=Northwind;Data Provider=SQLOLEDB.1"
' 建立选择语句.
strSQL = "SELECT ContactName, CompanyName, Address, " & _
"City FROM Customers WHERE (Region = 'SP')"
' 初始化ADO记录集.
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = strConnect
.LockType = adLockOptimistic
.Open strSQL
End With
' 设置表单记录集属性
Set Me.Recordset = rst
' 设置ControlSource属性
' 将表单项目与记录集字段对应.
txtContactName.ControlSource = "ContactName"
txtCompanyName.ControlSource = "CompanyName"
txtAddress.ControlSource = "Address"
txtCity.ControlSource = "City"
示例.rar
(29.75 KB, 下载次数: 41)
|
评分
-
1
查看全部评分
-
|