如何修复此 Access 2003 错误?数据输入自动生成值

发布于 2024-12-22 12:03:57 字数 1087 浏览 4 评论 0原文

我在 MS Access 中遇到了一个奇怪的数据输入错误,我希望有人可以帮助阐明为什么会发生这种情况以及如何修复它。

我有一个在 SQL Server 数据库中定义的数据表。定义如下,仅更改了字段名称。

CREATE TABLE [dbo].[MyTable](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [TextField1] [nvarchar](10) NOT NULL,
    [TextField2] [nvarchar](50) NOT NULL,
    [Integer1] [int] NOT NULL CONSTRAINT [DF_MyTable_Integer1]  DEFAULT (0),
    [Integer2] [int] NOT NULL,
    [LargerTextField] [nvarchar](300) NULL
) ON [PRIMARY]

从这个表的定义可以看出,它没有什么特别之处。我遇到的问题是 MS Access 2003 数据库中的链接数据表通过 ODBC 链接到该表。

在 SQL Server 中定义和创建数据表后,我打开工作 Access 数据库并链接到新表。我需要手动创建属于该表的记录。但是,当我开始添加数据行时,我注意到当我从 LargerTextField 跳出到新行时,LargerTextField 默认为“2',即使我没有输入任何内容,也没有在该字段上定义默认值?!

最初,我需要此字段为Null。我稍后会回来并通过更新例程填充数据。但是为什么 MS Access 会在我的字段中默认一个值,即使表的架构明确没有定义该值?有谁见过这个或知道为什么会发生这种情况?

编辑

一个快速更正,当我按 Tab 键进入 LargerTextField 时,该值默认为“2”,而不是当我按 Tab 键退出时。微小而微妙的差异,但可能很重要。

作为测试,我还创建了一个新的 MS 数据库并链接了表。我遇到了完全相同的问题。我认为这可能是 MS SQL Server 或 ODBC 的问题。

I'm experiencing an odd data entry bug in MS Access and I am hoping that someone can possibly help shed a bit of light on why this might be happening and how to fix it.

I have a data table that is defined in our SQL Server database. The definition is below, with only the field names changed.

CREATE TABLE [dbo].[MyTable](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [TextField1] [nvarchar](10) NOT NULL,
    [TextField2] [nvarchar](50) NOT NULL,
    [Integer1] [int] NOT NULL CONSTRAINT [DF_MyTable_Integer1]  DEFAULT (0),
    [Integer2] [int] NOT NULL,
    [LargerTextField] [nvarchar](300) NULL
) ON [PRIMARY]

As you can see from the definition of this table that there is nothing special about it. The problem that I am having is with a linked data table in an MS Access 2003 database that links through ODBC to this table.

After defining and creating the data table in SQL Server, I opened my working Access Database and linked to the new table. I need to manually create the records that belong in this table. However, when I started to add the data rows, I noticed that as I tabbed out of the LargerTextField to a new row, the LargerTextField was being defaulted to '2', even though I had not entered anything nor defined a default value on the field?!

Initially, I need this field to be Null. I'll come back later and with an update routine populate the data. But why would MS Access default a value in my field, even though the schema for the table clearly does not define one? Has anyone seen this or have any clue why this may happen?

EDIT

One quick correction, as soon as I tab into the LargerTextField, the value defaults to '2', not when I tab out. Small, subtle difference, but possibly important.

As a test, I also created a new, fresh MS Database an linked the table. I'm having the exact same problem. I assume this could be a problem with either MS SQL Server or, possibly, ODBC.

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

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

发布评论

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

评论(2

剑心龙吟 2024-12-29 12:03:57

哇,问题解决了。这不是一个错误,但它肯定不是我想要或预期的行为。

出现此行为的原因是我在字段 Integer1Integer2 中手动输入了数据。我手动输入 0 作为 Integer1 的值,并将 1 输入到 Integer2 中。我从未见过 Access 自动假定我的数据输入,但看起来它正在识别按顺序输入的数据。

作为测试,我输入了一条记录,其中 Integer1 设置为 1Integer2 设置为 2。果然,当我按 Tab 键进入 LargerTextField 时,3 的值已自动填充。

我讨厌这是一个由于用户无知而造成的问题,但是,老实说,在我过去 10 多年使用 MS Access 的过程中,我什至不记得曾经看到过这种行为。我几乎宁愿删除这个问题来挽回面子,但由于它让我措手不及,而且我是一个经验丰富的用户,我不妨将它留在 StackExchange 档案中,以供其他可能有相同经历的人使用。 :/

Wow, problem solved. This isn't a bug but it was certainly not behavior I desire or expected.

This behavior is occurring because of the data I am manually entering in fields Integer1 and Integer2. I am manually entering a 0 as the value of Integer1 and a 1 into Integer2. I've never seen Access automatically assume my data inputs, but it looks like it's recognizing data that is sequentially entered.

As a test, I entered a record with Integer1 set to 1 and Integer2 set to 2. Sure enough, when I tabbed into LargerTextField, the value of 3 was auto-populated.

I hate that this was a problem because of user ignorance but, I'll be honest, in my past 10+ years of using MS Access I can not recall even once seeing this behavior. I would almost prefer to delete this question to save face but since it caught me off guard and I'm an experienced user, I might as well leave it in the StackExchange archives for others who may have the same experience. :/

纵情客 2024-12-29 12:03:57

作为实验,启动一个全新的 Access DB 并连接到该表,看看是否获得相同的行为。我怀疑这个 Access DB 过去曾连接到这样的表并具有默认设置。 Access 有时会忘记:)

As an experiment fire up a brand-new Access DB and connect to this table to see if you get the same behavior. I suspect this Access DB was connected to a table like this in the past and had that default set. Access has trouble forgetting sometimes :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文