读取 dbf
首先先做准备工作,装个VFPODBC.msi文件,装好了看看你的odbc数据源里面系统dns里面是不是多了2个驱动
然后就是编码工作了
//此方式将dbf文件所在目录看作数据库,其中的dbf文件看作数据库表,表名即文件名(不加扩展名)。
//把打开的dbf文件导入DATASET,
//FilePath 是文件DBF的目录,tabname是dbf的文件名
public DataSet imp
{
string strConnection = @"Dsn=Visual FoxPro Tables;sourcedb=" + FilePath.Substring(0, FilePath.LastIndexOf("\\")) + ";sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";
//对于连接串,注意版本问题
string strSelect = "SELECT * FROM " + tabname;
OdbcConnection thisConnection = new OdbcConnection(strConnection);
thisConnection.Open();
OdbcDataAdapter thisAdapter = new OdbcDataAdapter(strSelect, thisConnection);
DataSet thisDataSet = new DataSet();
try
{
thisAdapter.Fill(thisDataSet,"dbf");
}
catch (Exception exec)
{
MessageBox.Show(exec.Message);
}
int table= thisDataSet.Tables[0].Rows.Count;
return thisDataSet;
}
//此方法是把DataSet放到数据库里面
//请确定你的DBF文件和你的表结构一样,要不插不进去
public static void SaveDbf(DataSet ds)
{
string sql = "select * from 表名";
SqlCommand cmd = new SqlCommand(sql, Connection);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(da);
da.Update(ds,"dbf");
}
http://download.microsoft.com/download/b/f/b/bfbfa4b8-7f91-4649-8dab-9a6476360365/VFPOLEDBSetup.msi