使用 OLE 将日期字段插入 Clipper 数据库

发布于 2024-08-17 19:10:01 字数 1579 浏览 9 评论 0原文

我们正在尝试将数据插入到 Clipper 数据库文件(带有 NTX 索引文件的 DBF 文件)中。

由于多种原因,我们无法更改数据库格式。

我们目前看到两个问题:

  1. 使用我们现有的代码,我们无法更新或利用 NTX 索引文件(我相信)。我们希望能够做到这一点。您知道可以执行此操作的 OLE 或 ODBC 驱动程序吗?

  2. 只要我们不包含日期,我们就可以将一行插入到 Clipper 数据库文件 (DBF) 中。如果我们包含任何格式的日期,我们都会收到错误。

一些示例代码:

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV");
string sql = "insert into TABLE (E, J, DATE, STARTTIME, ENDTIME) values ('1', '2', '2010-01-13' ,'08:12:12', '18:12:12')";

  OleDbCommand myCommand = new OleDbCommand(sql);
  myCommand.Connection = con;
  con.Open();
  myCommand.ExecuteNonQuery();
  myCommand.Connection.Close();

例外情况如下:

01/15/2010 12:50:31 {ERROR} ASITranslator.GUI.ASITranslatorGUI.insertSCH - Error in: Syntax error in INSERT INTO statement.-- StackTrace:    at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()

再次,没有 DATE 列,它可以正常工作。

是否有更好的提供程序可用于 Clipper 文件(该提供程序非常适合其他 DBF 文件)。

有什么想法吗?

We're trying to insert data into a clipper database file (DBF file with NTX index file).

For a variety of reasons, we cannot change the database format.

We are currently seeing two issues:

  1. With our existing code, we are not able to update or utilize the NTX index file (I believe). We would like to be able to do this. Do you know of an OLE or ODBC driver that can do this?

  2. We are able to insert a row into the clipper database file (DBF) as long as we do not include a date. If we include a date, in any format, we get an error.

Some example code:

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV");
string sql = "insert into TABLE (E, J, DATE, STARTTIME, ENDTIME) values ('1', '2', '2010-01-13' ,'08:12:12', '18:12:12')";

  OleDbCommand myCommand = new OleDbCommand(sql);
  myCommand.Connection = con;
  con.Open();
  myCommand.ExecuteNonQuery();
  myCommand.Connection.Close();

and the exception is something like:

01/15/2010 12:50:31 {ERROR} ASITranslator.GUI.ASITranslatorGUI.insertSCH - Error in: Syntax error in INSERT INTO statement.-- StackTrace:    at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()

Again, without the DATE column, it works fine.

Is there a better provider to use for Clipper files (that provider works great for other DBF files).

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恏ㄋ傷疤忘ㄋ疼 2024-08-24 19:10:01

似乎问题主要与 OLE DBF / dbase 驱动程序无法写入 Clipper 本机格式(这是 dbase III 的修改版本)有关。

要写入 Clipper 格式,需要使用此字符串:

Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Extended Properties="CollatingSequence=ASCII;DBQ=C:\DATA\8110FULL;DefaultDir=C:\DATA\8110FULL;Deleted=1;Driver={Microsoft dBase Driver (*.dbf)};DriverId=21;FIL=dBase III;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\test.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=600;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;";Initial Catalog=C:\DATA\8110FULL

这将允许写入文件,包括 DATE 格式。

但是,这不使用 NTX 索引文件(也不更新它们)。为此,我们似乎需要使用 CodeBase(或类似的)Clipper 驱动程序。

Seems the issue is primarily related to the OLE DBF / dbase driver is unable to write to the Clipper native format, which is a modified version of dbase III.

To write to the Clipper format, this string needs to be used:

Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Extended Properties="CollatingSequence=ASCII;DBQ=C:\DATA\8110FULL;DefaultDir=C:\DATA\8110FULL;Deleted=1;Driver={Microsoft dBase Driver (*.dbf)};DriverId=21;FIL=dBase III;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\test.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=600;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;";Initial Catalog=C:\DATA\8110FULL

This will allow one to write to the file, including the DATE format.

However, this does NOT use the NTX index files (nor does it update them). For that, it would appear that we would need to use the CodeBase (or similar) Clipper driver.

潦草背影 2024-08-24 19:10:01

首先,您似乎正在尝试为日期列添加“文本值”,无论它们是否采用日期格式。此外,如果在要使用变量的基于 Web 的应用程序中使用,则最好使用参数化查询。

String sql = "insert into YourTable ( fld1, fld2, DateFld1, DateFld2 ) "
  + "value ( ?, ?, ?, ? )";

OleDbCommand myCommand = new OleDbCommand(sql); 

OleDbParameter NewParm = new OleDbParameter( "parmFld1", 1 );
NewParm.DbType = DbType.Int32;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmFld2", 2 );
NewParm.DbType = DbType.Int32;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmDate1", DateTime.Now );
NewParm.DbType = DbType.DateTime;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmDate2", DateTime.Now );
NewParm.DbType = DbType.DateTime;
myCommand.Parameters.Add( NewParm );

然后继续连接、打开、执行和关闭...

First, it appears you are trying to add 'Text values' for the date columns regardless of them being in a date format. Additionally, if used in web-based applications where you would be using variables, you'd be best to use parameterized queries.

String sql = "insert into YourTable ( fld1, fld2, DateFld1, DateFld2 ) "
  + "value ( ?, ?, ?, ? )";

OleDbCommand myCommand = new OleDbCommand(sql); 

OleDbParameter NewParm = new OleDbParameter( "parmFld1", 1 );
NewParm.DbType = DbType.Int32;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmFld2", 2 );
NewParm.DbType = DbType.Int32;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmDate1", DateTime.Now );
NewParm.DbType = DbType.DateTime;
myCommand.Parameters.Add( NewParm );

NewParm = new OleDbParameter( "parmDate2", DateTime.Now );
NewParm.DbType = DbType.DateTime;
myCommand.Parameters.Add( NewParm );

Then continue with your connection, open, execute and close...

妖妓 2024-08-24 19:10:01

DSN-less 连接:(注意驱动程序和 FIL 字符串已更改为 Windows 7 中的名称)
它使用 Microsoft OLE DB Provider for ODBC Drivers (MSDASQL)。
该代码使用 .Net Framework Data Provider for ODBC (System.Data.Odbc),
不是 OLEDB (System.Data.OleDb) 的 .Net Framework 数据提供程序。
剪钳类型N-> OdbcType 双精度

 "Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Extended Properties=\"CollatingSequence=ASCII;DBQ=F:\\Folder;DefaultDir=F:\\Folder;Deleted=1;DRIVER=Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx);DriverId=21;FIL=dBASE III;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=600;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;\";Initial Catalog=F:\\Folder";

DSN-less connection : (Note the driver and FIL string changed to what called in Windows 7)
It use Microsoft OLE DB Provider for ODBC Drivers (MSDASQL).
The code use the .Net Framework Data Provider for ODBC (System.Data.Odbc),
Not the .Net Framework Data Provider for OLEDB (System.Data.OleDb).
Clipper type N-> OdbcType Double

 "Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Extended Properties=\"CollatingSequence=ASCII;DBQ=F:\\Folder;DefaultDir=F:\\Folder;Deleted=1;DRIVER=Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx);DriverId=21;FIL=dBASE III;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=600;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;\";Initial Catalog=F:\\Folder";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文