使用 ADO ,其连接字符串为:Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="Driver={Microsoft FoxPro VFP Driver (*.dbf)};UID=;SourceDB=c:\joo\jz.dbf;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
调试欢乐多
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public cmd As New ADODB.Command
请问???处怎么写?
cn.ConnectionString= "???"
cn.Open
cmd.CommandText = "??? "
cmd.ActiveConnection = cn
rs.Open cmd
能写个例子吗?谢啦
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim filepath As String
Dim filename As String
Dim fd As FieldPrivate Sub Command1_Click()
Dim i As String
Dim ff As String
dlg.Filter = "*.dbf|*.dbf"
dlg.ShowOpen
If dlg.filename = "" Then Exit Sub
ff = Dir(dlg.filename)
filepath = Left$(dlg.filename, (dlg.filename) - Len(ff))On Error GoTo aa
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(filepath, False, False, "foxpro 3.0;")
For X = 0 To db.TableDefs.Count - 1
'Ignore system tables...
If InStr(UCase(db.TableDefs(X).name), "MSYS") = 0 Then '为dbf表进行操作
Set rs = db.OpenRecordset(td) rs.MoveLast
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Me.Caption = "正在处理第" & i & "条纪录!,请稍侯!"
DoEvents '对表的操作
rs.MoveNext
Next '里重循环
Next '外重循环
db.Close
MsgBox ("运行完毕")
Me.Caption = "运行完毕"
Exit Sub
aa:
db.Close
MsgBox ("出错")
End Sub
filepath = Left$(dlg.filename, (dlg.filename) - Len(ff))
应为:filepath = Left$(dlg.filename, len(dlg.filename) - Len(ff))
偶是这样写的哪里不对请指教
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public cmd As New ADODB.Command
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Extended Properties='Driver={Microsoft FoxPro VFP Driver (*.dbf)};UID=;SourceDB=c:\joo\jz.dbf;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;'"
cn.Open
cmd.CommandText = "SELECT * FROM jz WHERE [deh] = 1830 "
cmd.ActiveConnection = cn
rs.Open cmd
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Extended Properties=""Driver={Microsoft FoxPro VFP Driver (*.dbf)};UID=;SourceDB=c:\joo\jz.dbf;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"" "
cn.Open
Driver={Microsoft FoxPro VFP Driver (*.dbf)};
改成
Driver={Microsoft Visual FoxPro Driver}
就打开了。。