DBF 上的 SQL UPDATE 语句的奇怪行为

发布于 2024-10-14 15:27:40 字数 1496 浏览 1 评论 0原文

我真的被一个看似简单的陈述所困扰。

我正在处理 DBF 表。当我在名为“DBF Viewer 2000”的程序中打开该文件时,它指出该文件是“FoxBase+/dBASE III PLUSE,无备忘录”。

如果我运行此 VB.NET 代码,


        Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & opt.path & "\" & ";Extended Properties=dBase III;"
        Dim oledbAdapterIns As New OleDbDataAdapter()
        Dim InsConnection As New OleDbConnection(ConnectionString)
        oledbAdapterIns = New OleDbDataAdapter()
        InsConnection = New OleDbConnection(ConnectionString)
        Try
            InsConnection.Open()
            Dim s As String
            s = "UPDATE LIBRIAZ SET LIBRIAZ.ULTNUM=6 WHERE LIBRIAZ.REGISTRO='CW' AND LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'"
            oledbAdapterIns.InsertCommand = New OleDbCommand(s, InsConnection)
            Dim rows As Integer = oledbAdapterIns.InsertCommand.ExecuteNonQuery()
        Catch ex As Exception
            Debug.Writeline(ex.Message)
        End Try
        oledbAdapterIns.Dispose()
        InsConnection.Dispose()

它运行时不会出现错误,但不会更新表。

现在奇怪的是:如果我删除三个条件之一

LIBRIAZ.REGISTRO='CW' AND LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'
for example

LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'
the UPDATE works, setting LIBRIAZ.ULTNUM to 6

这不是我删除哪个条件的问题,因为删除其中一个条件就足以使更新工作。

这几天我一直在试图弄清楚为什么会出现这种行为……现在我非常绝望。

有人知道吗?

i'm really stuck on a apparently simple statement.

I'm working on a DBF table. When I open the file in a program called "DBF Viewer 2000", it states that the file is a "FoxBase+/dBASE III PLUSE, no memo".

If i run this VB.NET code


        Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & opt.path & "\" & ";Extended Properties=dBase III;"
        Dim oledbAdapterIns As New OleDbDataAdapter()
        Dim InsConnection As New OleDbConnection(ConnectionString)
        oledbAdapterIns = New OleDbDataAdapter()
        InsConnection = New OleDbConnection(ConnectionString)
        Try
            InsConnection.Open()
            Dim s As String
            s = "UPDATE LIBRIAZ SET LIBRIAZ.ULTNUM=6 WHERE LIBRIAZ.REGISTRO='CW' AND LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'"
            oledbAdapterIns.InsertCommand = New OleDbCommand(s, InsConnection)
            Dim rows As Integer = oledbAdapterIns.InsertCommand.ExecuteNonQuery()
        Catch ex As Exception
            Debug.Writeline(ex.Message)
        End Try
        oledbAdapterIns.Dispose()
        InsConnection.Dispose()

it runs without error BUT not updating the table.

Now comes the weird: if I remove one of the three conditions

LIBRIAZ.REGISTRO='CW' AND LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'


for example

LIBRIAZ.ANNO='2011' AND LIBRIAZ.CHIAVE='ORD_REG'


the UPDATE works, setting LIBRIAZ.ULTNUM to 6

It's not a matter of which condition i remove, because it's enough to remove one of them to get the UPDATE working.

It's days I'm trying to figure why this behavior... now i'm pretty desperate.

Anyone have a clue?

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

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

发布评论

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

评论(1

动听の歌 2024-10-21 15:27:40

首先打动我的是你关于“没有备忘录”的第一条评论。当 dbf 文件具有备注字段时(如其他 SQL 中的 blob,用于存储较大的非标准数据元素,例如嵌入图片、Excel 文件、XML 或其他内容)。文件“集”将是这样的。

YourTable.dbf  (main table)
YourTable.cdx  (index file associated with just this table)
YourTable.fpt  (memo file associated with just this table)

主 .dbf 有一个文件指针系统,它是存储其内容的 .FPT 文件中以字节为单位的偏移量(如果适用)。因此,我会首先考虑找到丢失/损坏的 .fpt 文件。

接下来,在您的更新语句中,由于您只进行直接更新,而不是基于另一个表的相关更新,因此您不需要为每个字段设置别名...尝试精简为...

s = "UPDATE LIBRIAZ SET ULTNUM = 6 WHERE REGISTRO='CW' AND ANNO='2011' AND CHIAVE='ORD_REG'"               

The first thing that hits me is your first comment about "no memo". When a dbf file has a memo field (like a blob in other SQL to store larger non-standard data elements like embedded pictures, Excel files, XML, or whatever). The files "sets" would be such as

YourTable.dbf  (main table)
YourTable.cdx  (index file associated with just this table)
YourTable.fpt  (memo file associated with just this table)

The main .dbf has a file pointer system that is an offset in bytes in the .FPT file where it's contents are stored (if applicable). So, I would see about finding that missing / corrupted .fpt file first.

Next, in your update statement, since you are only doing a direct update and not a correlated update based on another table, you don't need to ALIAS every field... Try stripping down to...

s = "UPDATE LIBRIAZ SET ULTNUM = 6 WHERE REGISTRO='CW' AND ANNO='2011' AND CHIAVE='ORD_REG'"               
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文