BDE 提示“未找到字段”但场存在

发布于 2024-10-18 12:55:28 字数 521 浏览 1 评论 0原文

我对我的数据库表之一有以下查询:

select count(*) as mycount
  from mytable
 where fieldone = :fieldone
   and fieldtwo = :fieldtwo

参数已正确加载到查询中(均为字符串类型)。

当我在应用程序外部运行此查询(例如,通过 dbexplore)并将参数替换为实际值时,我得到了正确的结果。但是,当在应用程序中运行它时,我在 Query.Open 调用中收到 Field 'fieldtwo' not found 错误。

当该字段实际存在时,为什么 BDE 找不到该字段?

更新:以下查询在第一个查询(失败的查询)之后立即执行,在应用中运行良好:

select *
  from mytable
 where fieldone = :fieldone
 order by fieldone, fieldtwo

I have the following query to one of my database tables:

select count(*) as mycount
  from mytable
 where fieldone = :fieldone
   and fieldtwo = :fieldtwo

Parameters are correctly loaded into the query (both of type String).

When I run this query outside the app (for instance, through the dbexplore) and replace the parameters with the actual values, I get the correct result. But when running it in the app, I get a Field 'fieldtwo' not found error, right on the Query.Open call.

Why would the BDE not find this field, when it actually exist?

Update: The following query, executed right after the first one (the one that fails), works fine in the app:

select *
  from mytable
 where fieldone = :fieldone
 order by fieldone, fieldtwo

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

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

发布评论

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

评论(7

流星番茄 2024-10-25 12:55:28

最好的猜测是您已经在查询中填充了字段列表,这会覆盖查询中基础字段的任何概念,并且会导致无数混乱。

右键单击查询,选择字段编辑器,清除其中的所有值,然后选择“添加所有字段”,这将导致执行查询后出现缺失的字段。

我认为如果执行查询时没有定义的字段,它应该自动填充字段,因此清除字段后您可能不需要选择“添加所有字段”。

The best guess is that you have populated the field list in the query, this overrides any concept of the underlying fields that are in the query and is a cause of countless confusion.

Right click on the query, pick the fields editor clear all the values that are there and then choose 'add all fields' that should cause the missing field to appear once the query is executed.

I think it should auto-populate the fields if there are no defined fields when the query is executed, so you may not need to choose 'add all fields' after clearing the fields.

冬天旳寂寞 2024-10-25 12:55:28

每当我们遇到这样的问题时,我们倾向于从表单中删除查询并在运行时动态创建它...这取决于它在表单中的根深蒂固程度...

例如,如果您有一个数据感知控件正在查看“ fieldtwo”尝试在底层数据集更新时获取一些数据,然后它会触发这样的错误,但是当您编写这样的代码时会更明显

SomeEdit.Text = Query.FieldByName("fieldtwo").AsString;

这样它会落在相关行而不是打开(触发相关事件)

Whenever we come across a problem like this we tend to remove the query from the form and create it dynamically at run time... It depends how ingrained into the form it is...

E.g. If you have a data aware control looking at "fieldtwo" which tries to fetch some data when the underlying data set gets updated then it'll trigger an error like this, but it's more obvious when you've written code such

SomeEdit.Text = Query.FieldByName("fieldtwo").AsString;

That way it falls over on the relevant line instead of the open (triggering a related event)

阪姬 2024-10-25 12:55:28

打开查询之前使用Query1.SQL.Clear;语句清除查询内容。

其他原因可能是您正在打开其他可能没有指定字段的数据库。确保应用程序和 dbexplore 中的 DatabaseName's 相同

Clear the query content using Query1.SQL.Clear; statement before opening it.

Other reason can be you are opening other database which may not have the specified field. Be sure that both the DatabaseName's in your app and dbexplore are same

红颜悴 2024-10-25 12:55:28

当我打开 SQLExplorer 并且应用程序同时访问数据库时,我曾经遇到过 BDE 问题(但我遇到了类似的错误),尝试关闭资源管理器它可能会有所帮助,如果没有,我会将 SQL 构建为不带参数的文本并尝试它是否有效(如果在您的情况下可能的话)。

I used to face porblems with BDE when i have SQLExplorer open and the app accesses the DB at the same time (but i had errors like ), try closing the Explorer it may help, if not i would build the SQL as text without the Parameters and try if it works then (if its possible in your situation).

平安喜乐 2024-10-25 12:55:28

我不使用参数,所以我只是在这里抓住救命稻草。我仍然经常使用 BDE,但不是专家。我发现我回避更复杂的表达(你的不是!),因为 BDE 会给你带来像这样的小“惊喜”。

也许添加括号:

 where (fieldone = :fieldone)
 and (fieldtwo = :fieldtwo)

或者,单引号或双引号(这可能会使情况变得更糟?)

 where (fieldon = ":fieldone")
 and   (fieldtwo = ":fieldtwo")

或者,为了探索问题,删除“and fieldtwo = :fieldtwo”行并查看它是否运行。

您是否可以使用 StringReplace 进行自己的参数替换,如下所示

 Query1.SQL.Text := StringReplace(Query1.SQL.Text, ":fieldone", "MyVarName",[rfReplaceAll   ]); 

I don't use parameters, so I'm just grabbing at straws here. I still use the BDE regularly, but am no expert. I find I shy away from more complex expressions (which yours is not!) because of the little "surprises" like this that the BDE throws at you.

Perhaps adding parentheses:

 where (fieldone = :fieldone)
 and (fieldtwo = :fieldtwo)

Or, single or double quote signs (this probably will make it worse?)

 where (fieldon = ":fieldone")
 and   (fieldtwo = ":fieldtwo")

Or, to explore the problem, remove the "and fieldtwo = :fieldtwo" line and see if it runs.

Would it be possible for you to do your own parameter substitution with a StringReplace as in

 Query1.SQL.Text := StringReplace(Query1.SQL.Text, ":fieldone", "MyVarName",[rfReplaceAll   ]); 
奈何桥上唱咆哮 2024-10-25 12:55:28

如果通过Create DataSet方法在内存中创建ClienDataSet,则应检查TFieldDefs属性,该属性必须具有不同的字段名称或未创建

If you are creating a ClienDataSet in memory by the Create DataSet method, you should check the TFieldDefs property, which must have a different field name or not created

戒ㄋ 2024-10-25 12:55:28

我遇到了一个奇怪但小问题,我会发布,以防有​​一天它会对某人有所帮助。

uRegPeople.pas

with frmEditPerson do
  begin
    PersonID := qryPerson.FieldByName(ID).AsInteger;
    ...
  end;

我在 frmRegPeoplefrmEditPerson 中都有 qryPerson,通过使用 with > 我正在引用 frmEditPerson.qryPerson,但我想引用 frmRegPeople.qryPerson。然后我需要更改为以下代码。

with frmEditPerson do
  begin
    PersonID := Self.qryPerson.FieldByName(ID).AsInteger;
    ...
  end;

// Explanation
// qryPerson --> frmEditPerson.qryPerson;
// Self.qryPerson --> frmRegPeople.qryPerson;

I was having a weird but small problem, I'll post in case it will help someone in some day.

uRegPeople.pas

with frmEditPerson do
  begin
    PersonID := qryPerson.FieldByName(ID).AsInteger;
    ...
  end;

I had qryPerson both in frmRegPeople and in frmEditPerson, by using with I was referencing to frmEditPerson.qryPerson, however I wanted to reference to frmRegPeople.qryPerson. Then I need to change to the following code.

with frmEditPerson do
  begin
    PersonID := Self.qryPerson.FieldByName(ID).AsInteger;
    ...
  end;

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