???我想用SQL语句访问一个dbf表,是否是这样???

slpan 2003-04-01 08:43:11
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * form 表名"
Set DataGrid1.datasource = Adodc1
如果是DBF库它的表名是否要加扩展名.DBF?
如果不对,请指出,多谢。
...全文
32 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyu5188 2003-04-04
  • 打赏
  • 举报
回复
你主要是更改连接字符串。你的.dbf文件是什么版本的,是foxpro的还是早期Dbase格式的?
示例如下:
使用ADO控件:
foxpro格式的(.dbf为自由表):
Private Sub command1_click()
Dim cnstr As String,sqlstr as string
cnstr = "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=;" & app.path & "\data;" & _
"Exclusive=No"
adodc1.connectionstring=cnstr
sqlstr="select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
adodc1.recordsource=sqlstr
adodc1.refresh
Set DataGrid1.DataSource = adodc1
DataGrid1.Refresh
End Sub
以上示例程序的作用是将XXX.dbf表中的数据显示在datagrid1控件中。

DBASE格式的:
Private Sub Form_Load()
Dim cnstr As String,sqlstr as string
cnstr = oConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=" & app.path & "\data;"
adodc1.connectionstring=cnstr
sqlstr="select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
adodc1.recordsource=sqlstr
adodc1.refresh
Set DataGrid1.DataSource = adodc1
DataGrid1.Refresh
End Sub

以上示例程序的作用是将XXX.dbf表中的各列的第一条记录的各列数据分别显示在不同的textbox控件中。

几点说明:app.path是取得应用程序的当明目录,假设你的就用程序目录为:c:\myprg下,数据文件在c:\myprg\data目录下。那么app.path & "\data" 就代表了c:\myprg\data
即 app.path是取的相对路径,你也可以使用绝对路径c:\myprg\data.
在你的程序中要将我写的示例程序中相应的地方进行修,如表名,数据源路径等。

dragon525 2003-04-01
  • 打赏
  • 举报
回复
Dim str As String
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\data.mdb"
Adodc1.ConnectionString = str
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 表"
Adodc1.Refresh

如果是DBF 那么需要改变connectionString

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧