将空值读取为空而不是默认值
如何在 C# 中从“dbf”文件中读取空值。 目前,在读取 dbf 文件时,文件中的空值会自动转换为默认值。 就像空的小数字段被转换为“0.000”。 有人可以帮助您按原样读取空字段而不是默认值吗?
How to read the empty values from the "dbf" file in C#.
Currently while reading the dbf files, the empty values in the file are automatically getting converted to default values.
Like empty decimal field is converted to "0.000".
Can someone please help in way to read the empty fields as they are and not as default values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.dbf 文件格式可以追溯到计算的石器时代。它从来没有“空”列值的概念,未分配的字段将获得默认值。直到 FoxPro 才出现对可为空列的支持。我认为你所要求的是不可能的。
The .dbf file format dates back to the stone age of computing. It never had a notion of an "empty" column value, unassigned fields would get a default value. Support for nullable columns didn't come around until FoxPro. I reckon what you ask for isn't possible.
您可以将变量(至少是值类型)声明为可空类型:
如果该字段中没有值,则应将其保留为 null 并且不设置为默认值。
Can you declare your variables (at least the value types) as nullable types:
Then if there's no value in the field it should be left as null and not set to a default value.
decimal
是所谓的 值类型并且它不能为空,这可能就是您获得这些默认值的原因。但是,大多数数据库都有空值的概念 (DbNull< /code>
),所以这很可能只是正确读取值的问题。如果您发布一些代码,我们应该能够帮助您。
decimal
is a so-called value type and it cannot be null, which is probably why you are getting those default values. However, most databases have a notion of empty values (DbNull
), so it would most likely just be a question of reading the value correctly. If you post some code we should be able to help you.