c#通过OleDb访问dbf数据库

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/tedy/article/details/6174345

一、

下载VFPOLEDBSetup.mis

 

二、

连接字符串:Provider=vfpoledb;Data Source=dbf文件路径;Collating Sequence=machine;

 

三、

1.获取有效数据(不带删除标记)

select  * from **.dbf

 

2.获取所有数据(包括带删除标记和有效数据)

 

先执行语句:SET DELETED OFF

再执行:select  * from **.dbf

 

3.获取删除数据(带删除标记的)

 

先执行语句:SET DELETED OFF  ----(不知道为什么,一定先执行这句,再下面那句那句,才有删除数据)

再执行:select  * from **.dbf where Deleted()

展开阅读全文

ADO 通过 OLEDB 访问 Access 数据库

12-28

如果您要打开受密码保护数据库, 您可使用下列三种语法之一: rnrn Dim MyConn As New ADODB.Connectionrn MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"rn MyConn.Properties("Data Source") = "C:\...\JetPassword.MDB"rn MyConn.Properties("Jet OLEDB:Database Password") = "MyPwd"rn MyConn.Openrn rn- 或 - rn Dim MyConn As New ADODB.Connectionrn Dim strConn As Stringrnrn strConn = "Data Source=C:\...\JetPassword.MDB;" & _rn "Jet OLEDB:Database Password=MyPwd"rn MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"rn MyConn.Open strConnrn- 或 - rn Dim MyConn As New ADODB.Connectionrn Dim strConn As Stringrnrn strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _rn "Data Source=C:\...\JetPassword.MDB;" & _rn "Jet OLEDB:Database Password=MyPwd"rn MyConn.Open strConnrnrn如果您要打开 Jet 安全, 使用数据库, 可使用下列三种语法之一: Dim MyConn As New ADODB.Connectionrnrn MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"rn MyConn.Properties("Data Source") = "C:\...\JetSecurity.MDB"rn MyConn.Properties("Jet OLEDB:System database") = "C:\...\System.MDW"rn MyConn.Open UserID:="Admin", Password:="MyPwd"rn- 或 - rn Dim MyConn As New ADODB.Connectionrn Dim strConn As Stringrnrn strConn = "Data Source=C:\...\JetSecurity.MDB;" & _rn "Jet OLEDB:System database=C:\...\System.MDW"rn MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"rn MyConn.Open ConnectionString:=strConn, _rn UserID:="Admin", Password:="MyPwd"rn rn- 或 - rn Dim MyConn As New ADODB.Connectionrn Dim strConn As Stringrnrn strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"rn "Data Source=C:\...\JetSecurity.MDB;" & _rn "Jet OLEDB:System database=C:\...\System.MDW"rn MyConn.Open ConnectionString:=strConn, _rn UserID:="Admin", Password:="MyPwd"rnrnrnrnrn这个应该是VB吧? 论坛

通过ODBC数据源访问vfp的dbf数据文件

06-06

1.配置ODBC数据源fdb,选择驱动程序为:Microsoft dBase Driver(*.dbf) rn2.执行下面的程序段: rn package database; rn rnimport java.lang.*; rnimport java.sql.*; rnimport java.io.InputStream; rnimport java.util.ArrayList; rn rn/** rn * Title: rn * Description: rn * Copyright: Copyright (c) 2006 rn * Company: rn * @author not attributable rn * @version 1.0 rn */ rn rnpublic class OdbcTest rn private static Connection conn = null; rn private static Statement stmt = null; rn private static String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver"; rn private static String URL = "jdbc:odbc:fdb"; rn rn public OdbcTest() rn rn rn public Connection getConn() rn Connection conn1 = null; rn try rn Class.forName(DRIVER); rn System.out.println("success step 1"); rn rn catch (java.lang.ClassNotFoundException e) rn e.printStackTrace(); rn rn try rn conn1 = DriverManager.getConnection(URL); rn if (conn1 == null) rn System.out.println("conn1 is null:"); rn rn rn catch (Exception ex) rn ex.printStackTrace(); rn rn rn return conn1; rn rn rn public ArrayList getColumnList() rn ArrayList result = new ArrayList(); rn ResultSet rs = null; rn try rn DatabaseMetaData dbMetaData = this.getConn(). rn getMetaData(); rn rs = dbMetaData.getColumns(null, null, rn "career.dbf", null); rn while (rs.next()) rn String colName = rs.getString(4); rn result.add(colName); rn System.out.println(colName); rn rn rn rn catch (Exception ex) rn ex.printStackTrace(); rn rn finally rn try rn if (rs != null) rn rs.close(); rn rn rn catch (SQLException ex) rn ex.printStackTrace(); rn rn rn System.out.println(result.size()); rn return result; rn rn rn public void selectTable() rn ResultSet rs = null; rn Statement stmt = null; rn String sql2 = "select * from career.dbf"; rn try rn conn=getConn(); rn stmt=conn.createStatement(); rn rs = stmt.executeQuery(sql2); rn while(rs.next()) rn rn System.out.println(rs.getString(1)); rn rn catch (Exception ee) rn ee.printStackTrace(); rn rn rn rn public static void main(String args[]) rn OdbcTest odbctest = new OdbcTest(); rn odbctest.getColumnList(); rn odbctest.selectTable() ; rn rn rn rn rn rn执行odbctest.getColumnList();得不到任何结果. rn rn执行odbctest.selectTable() 报错; rnjava.sql.SQLException: [Microsoft][ODBC dBase Driver] 外部表不是预期的格式。 rn at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958) rn at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115) rn at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111) rn at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338) rn at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253) rn at database.OdbcTest.selectTable(OdbcTest.java:172) rn at database.OdbcTest.main(OdbcTest.java:187) rn请高手指点,多谢多谢! 论坛

没有更多推荐了,返回首页