使用 OLE 将日期字段插入 Clipper 数据库
我们正在尝试将数据插入到 Clipper 数据库文件(带有 NTX 索引文件的 DBF 文件)中。
由于多种原因,我们无法更改数据库格式。
我们目前看到两个问题:
使用我们现有的代码,我们无法更新或利用 NTX 索引文件(我相信)。我们希望能够做到这一点。您知道可以执行此操作的 OLE 或 ODBC 驱动程序吗?
只要我们不包含日期,我们就可以将一行插入到 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:
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?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎问题主要与 OLE DBF / dbase 驱动程序无法写入 Clipper 本机格式(这是 dbase III 的修改版本)有关。
要写入 Clipper 格式,需要使用此字符串:
这将允许写入文件,包括 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:
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.
首先,您似乎正在尝试为日期列添加“文本值”,无论它们是否采用日期格式。此外,如果在要使用变量的基于 Web 的应用程序中使用,则最好使用参数化查询。
然后继续连接、打开、执行和关闭...
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.
Then continue with your connection, open, execute and close...
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 双精度
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