|
楼主 |
发表于 2009-12-14 19:05
|
显示全部楼层
我自己尝试解决了一下,解决了一半,呵呵:编码中provider处要加MSDASQL.1,即:
With conn
.Provider = "MSDASQL.1;Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;"
.ConnectionString = "SourceDB=" & "D:\交易策略\dbf 连接程序\tt" ' & "\" & WN
.Open
End With
整段程序如下:
Sub 连接进销存表数据库()
Dim conn As ADODB.Connection
Dim WN As String
Dim sSql As String
Dim Tablename As String
Dim Columnname As String
Dim i As Integer
Dim rst As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Dim db As Database
Dim PriceGap As Long
WN = "sample.dbf"
Tablename = "sample"
Columnname = "name"
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
With conn
.Provider = "MSDASQL.1;Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;"
.ConnectionString = "SourceDB=" & "D:\交易策略\dbf 连接程序\tt" ' & "\" & WN
.Open
End With
If conn.State = 1 Then
MsgBox "连接成功!"
If rst.State = 1 Then
MsgBox "记录集打开成功!"
End If
sSql = "alter table " & Tablename & " add column " & Columnname & " long" '在表中加入一个新字段(列)
conn.Execute sSql
sSql = "UPDATE " & Tablename & " SET name = 1" '将新加入的字段赋值为1
conn.Execute sSql
rst.Open Source:=Tablename, ActiveConnection:=conn.ConnectionString, CursorType:=adOpenKeyset, LockType:=adLockOptimistic
Set rst2 = rst.Clone
conn.Close
End If
Set conn = Nothing
End Sub
其中rst.Open Source:=Tablename, ActiveConnection:=conn.ConnectionString, CursorType:=adOpenKeyset, LockType:=adLockOptimistic
这一句又有问题了,提示:ODBC 驱动程序不支持所需的属性,请高手帮忙看看,谢谢~~!!!!
[ 本帖最后由 yyy811240 于 2009-12-14 19:06 编辑 ] |
|