100分问题,在C#中,操纵vfp的 dbf数据问题?

imagingboy 2003-10-20 04:44:33
我正在做一个导数据小程序,将.dbf中的数据通过指定接口导入到sql 2000中。
我的连接字串为:
connString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=dBASE IV;User ID=Admin;Password=" ;
path为 dbf文件所在的目录。
omdText="select * from xs" xs为dbf文件
执行代码:

///<summary>
///连接到 Visual FoxPro 数据库。
///</summary>
OleDbConnection oConn=new OleDbConnection();
oConn.ConnectionString=connString;

///<summary>
///创建 DataAdapter。
///</summary>
OleDbDataAdapter odr = new OleDbDataAdapter();

///<summary>
///创建带 select 语句的 Command 对象.
///</summary>
OleDbCommand omd = new OleDbCommand();
omd.CommandText=omdText ;
omd.Connection=oConn;
///<summary>
///创建 dataSet 对象.
///</summary>
DataSet ds= new DataSet() ;
try
{
oConn.Open();
odr.SelectCommand=omd ;
odr.Fill(ds,"strFee");
return ds ;
}
catch(Exception a)
{
oConn.Close();
throw;
}

当代码执行到odr.Fill(ds,"strFee");一句时抛出异常{"外部表不是预期的格式" }
但是我使用sql查询分析器:执行
select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=C:\Documents and Settings\Administrator\桌面\财政厅','select * from [xs.DBF]')

可以查看道数据,我不知道到底是什么地方出了错误?请高手指点!!!

...全文
50 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Edelweissobject 2003-12-09
  • 打赏
  • 举报
回复
楼主,你应该用ODBCConnection,OLEDBConnection不支持dbf文件。以前我用的是.net2002,还要重新安装ODBC,现在.net2003已经集成了ODBC驱动了,看看ODBC驱动很容易实现的。
public OdbcConnection VFDB=new OdbcConnection();//连接DBF文件
string AppPath=Application.StartupPath+"\\";
string Constring="SourceType=DBF;SourceDB="+AppPath+";Driver={Microsoft Visual FoxPro Driver}";
VFDB =new OdbcConnection(Constring);
VFDB.Open();
dotnba 2003-12-09
  • 打赏
  • 举报
回复
string FileName = "G:\\AcceptData\\022003050001-3.dbf";
string name = null;
FileInfo file = new FileInfo(FileName);
name = file.Name;//文件名
string path = file.Directory.FullName + "\\"; //文件目录
string strConnection = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + path;
string strSelect="SELECT * FROM " + name;
OdbcConnection thisConnection = new OdbcConnection(strConnection);
thisConnection.Open();
OdbcDataAdapter thisAdapter = new OdbcDataAdapter(strSelect,thisConnection);
DataSet thisDataSet = new DataSet();
try
{
thisAdapter.Fill(thisDataSet,name);
}
catch(Exception exec)
{
MessageBox.Show(exec.Message);
return;
}
this.dataGrid1.DataSource = thisDataSet.Tables[name];
====================================================
葬我于高山之上兮,望我大陆。大陆不可见兮,只有痛哭。

葬我于高山之上兮,望我故乡。故乡不可见兮,永远不忘。

天苍苍,野茫茫,山之上,国有殇。
====================================================
rgbcn 2003-10-21
  • 打赏
  • 举报
回复
see

http://expert.csdn.net/Expert/topic/2140/2140302.xml?temp=.2276728
imagingboy 2003-10-21
  • 打赏
  • 举报
回复
兄弟们帮帮我吧! 到底是什么原因 。。。。。。
kuangren 2003-10-20
  • 打赏
  • 举报
回复
http://mscenter.edu.cn/forum/xml/board/dotnet/csharp/passage/2003-09-10%2014-26-42--56.xml?temp=0.249735756893519

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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