关于 ADO中 AutoGenerateValue的使用?

hk_c 2006-11-20 08:10:17
table customer(id int identity(1,1), name nvarchar)

ADOQuery->SQL->Text = "select * from customer";

ADOQuery->Insert();
....
ADOQuery->Post();

ADODataSet, ADOTable或ADOQuery 添加 id 的永久字段 idField, 将AutoGenerateValue设成arAutoInc, 为什么, 当ADOQuery Post(), 还是没有拿到新建的id值, 还是为0???

AutoGenerateValue是如何使用的呢?

相关问题回答:
http://community.csdn.net/Expert/TopicView3.asp?id=5171431
...全文
203 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2006-11-21
  • 打赏
  • 举报
回复
Use AutoGenerateValue to indicate when field values can be generated by the database. Such fields include autoincrement fields and fields with default values.

Some database drivers can't determine which fields can have values supplied automatically by the server. This can lead to problems when posting edits. For these cases, applications can provide this information by setting the AutoGenerateValue property. Use this property to indicate whether the field is an autoincrement field (arAutoInc), a field with a default value (arDefault), or a field whose value is not automatically generated (arNone).

AutoGenerateValue is not always required. Fields with an AutoGenerateValue property of arNone may still be updated if the driver supplies metadata that indicates it has a default value or an autoincrement value. However, it is good practice to supply this information because not all drivers supply this metadata.
If you do use AutoGenerateValue for any fields that have values generated by the database, you must set AutoGenerateValue to arAutoInc or arDefault on every field whose value is automatically generated by the database. This is because when records are posted, the application immediately executes a query to fetch the automatically-generated values. If you leave an automatically-generated field with AutoGenerateValue set to arNone, this query looks for a record with a blank value on that field, which will fail to locate the correct record.
Warning:
AutoGenerateValue can fail in some cases when the automatically-generated field value is on a key field. This is because the query that re-fetches the new field value can't always uniquely locate the record that was just posted.

Note:
Trying to change the AutoGenerateValue property when the field's dataset is open generates an exception. Thus, AutoGenerateValue only works with persistent field components, which remain when the dataset is closed.

daydayup234 2006-11-21
  • 打赏
  • 举报
回复
ADOQuery->fresh();
看看

如果再不行,close再open看看
hk_c 2006-11-21
  • 打赏
  • 举报
回复
顶起来

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧