感谢您使用微软产品。建议您能提供详细的错误信息。如果您能重现这个错误,建议您提供具体的步骤和代码,大家可以根据它做深入地分析。下面是我以前参与过的一个Foxpro在.NET下的一个问题的讨论,供您参考:////////////////////////////////////////////////////////////////////////////////////////////////////////////在您使用OleDB时,您的机器上是否安装了Visual Foxpro OleDB provider? 您需要安装Visual Foxpro 7.0来安装Visual Foxpro OleDB provider。请您参阅下面的网页:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfoxgen7/html/usingaspnetwithvfp7.asp 对于Visual FoxPro 7.0以前的版本,我们可以通过odbc来进行连接。建议您参照下面的步骤:1。下载native Visual FoxPro odbc provider:http://msdn.microsoft.com/vfoxpro/downloads/odbc.asp2. 安装ODBC .NET data provider http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml3. 这样,您可以通过odbc, 像在非.NET环境下访问Foxpro一样在您的aspx中访问Foxpro. 您可以参阅下面的网页:http://www.able-consulting.com/ADO_Conn.htm////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////您可能需要注意下面的几点:1。 请确保您在您的项目中引用了Microsoft.Data.Odbc2。 请确保您安装了下面这个补丁:http://support.microsoft.com/default.aspx?scid=KB;EN-US;q319243& 3。 请确保aspnet账号在数据库文件上的权限。下面是我做的test步骤:1。 下载native Visual FoxPro odbc provider:2。 安装ODBC .NET data provider http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml3。 安装了下面这个补丁:http://support.microsoft.com/default.aspx?scid=KB;EN-US;q319243& 4。 在vs.net中生成C# Web Applicatio project.5. 在“d:\vpr"目录中生成Visual Foxpro 6.0 数据库 (Books.dct)6. Add Reference: Microsoft.Data.Odbc;下面是我的代码,可以成功生成Datagrid:///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using Microsoft.Data.Odbc;namespace vfp { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here string constring=@"Driver={Microsoft Visual FoxPro Driver};" + @"SourceType=DBF;"+ @"SourceDB=d:\vpr\;"+ @"Exclusive=No"; OdbcConnection con=new OdbcConnection(constring); OdbcCommand com=con.CreateCommand(); com.CommandText=@"select * from books"; con.Open(); OdbcDataReader reader=com.ExecuteReader(); DataGrid1.DataSource=reader; DataGrid1.DataBind(); con.Close(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////
对于Visual FoxPro 7.0以前的版本,我们可以通过odbc来进行连接。建议您参照下面的步骤:1。下载native Visual FoxPro odbc provider:http://msdn.microsoft.com/vfoxpro/downloads/odbc.asp2. 安装ODBC .NET data provider http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml3. 这样,您可以通过odbc, 像在非.NET环境下访问Foxpro一样在您的aspx中访问Foxpro. 您可以参阅下面的网页:http://www.able-consulting.com/ADO_Conn.htm////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////您可能需要注意下面的几点:1。 请确保您在您的项目中引用了Microsoft.Data.Odbc2。 请确保您安装了下面这个补丁:http://support.microsoft.com/default.aspx?scid=KB;EN-US;q319243& 3。 请确保aspnet账号在数据库文件上的权限。下面是我做的test步骤:1。 下载native Visual FoxPro odbc provider:2。 安装ODBC .NET data provider http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml3。 安装了下面这个补丁:http://support.microsoft.com/default.aspx?scid=KB;EN-US;q319243& 4。 在vs.net中生成C# Web Applicatio project.5. 在“d:\vpr"目录中生成Visual Foxpro 6.0 数据库 (Books.dct)6. Add Reference: Microsoft.Data.Odbc;下面是我的代码,可以成功生成Datagrid:///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Data.Odbc;namespace vfp
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here string constring=@"Driver={Microsoft Visual FoxPro Driver};" +
@"SourceType=DBF;"+
@"SourceDB=d:\vpr\;"+
@"Exclusive=No"; OdbcConnection con=new OdbcConnection(constring); OdbcCommand com=con.CreateCommand();
com.CommandText=@"select * from books"; con.Open();
OdbcDataReader reader=com.ExecuteReader(); DataGrid1.DataSource=reader;
DataGrid1.DataBind(); con.Close();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
} ////////////////////////////////////////////////////////////////////////////////////////////////////////////
希望对您有所帮助。
-微软全球技术中心 -zgh
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
一些资料了!
string MySelectCommandText = @"select * from " + TableName;
OleDbConnection MyConn=new OleDbConnection(myConnText);
OleDbCommand MySqlCommand=new OleDbCommand();
MySqlCommand.Connection =MyConn;
MySqlCommand.CommandText=@"SET NULL Off\r\n";//SET EXACT ON\r\nSET DELETED ON\r\n
OleDbDataAdapter MyDataAdapter=new OleDbDataAdapter(MySelectCommandText,MyConn);
DataSet MyDs=new DataSet();
MyConn.Open();
MySqlCommand.ExecuteNonQuery();
MyDataAdapter.Fill(MyDs,TableName); //在这行出错。
MyConn.Close();
MyDataAdapter.Dispose();
catch(OleDbException Ex)
{
MessageBox.Show("Error:LoadData OleDb" +Ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return new DataSet();
}
catch(Exception Ex)
{
MessageBox.Show("Error:LoadData" + Ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return new DataSet();
}
}
return MyDs;
myConnText=@"Provider=VFPOLEDB.1;Data Source="+ cf.FilePath + ";Exclusive=No;Collating Sequence=PINYIN;Deleted=On";
使用odbc.net时 .net环境中的错误提示为:在odbc.net中的错误提示为:
数据提供程序或其他服务返回E_FAIL状态。
而是 s6 列,定义为:n(8,3),按 fox 的解释是:1位小数点、3位小数、4位正数,由此推断表头就是这样描述的,OLE DB 驱动也是这样认为此列的结构的。
有趣的是,在 fox里的replace、SQL-insert、SQL-Update可以使整数位最大达到8位,原则上整数+小数点+小数=8
所以在第一行出现了 s6=20021016 的数据,但是Oledb 驱动只能认识s6的整数为<=5,所以出错。
解决方案:
1.逻辑删除第一行,其他数据就能正确读取
2.如果要读取第一行
SELECT alltr(str(s6)) AS Expr1 from show128 where s1="000000"
alltr(str(s6)) ---可以变换,利用合理转换…
3.写第一行,用发送 SQL-Update 的方式解决。