使用数据集时不生成sqlce自动递增id
我正在编写一个使用 sql 精简版的程序。 在此程序中,我想使用数据集类功能加载一对多相关数据。 加载后,数据可以显示在表单上,并由用户进行调整。没问题,当使用 sqlceDataAdapter 时,数据将成功写入磁盘。
但是...我也想添加新数据,因此在父表中添加数据,在子表中添加数据。这些数据将首先添加到数据集中。之后,当用户想要保存新数据时,我想将其写入数据库。要在子表中添加数据,我需要知道父数据的 id,这就是问题所在! id指定为整数,自动递增,向数据集添加数据时,不会自动生成id。
当将数据写入数据库时,id由sqlce填充,但我在创建子id时已经需要这些id了。
有人知道如何解决这个问题,而不需要自己生成 ids 吗?
谢谢 !
i'm writing a program which uses sql compact edition.
in this program i would like to load one-many related data using the dataset class functionality.
after loading, the data can be shown on the form, and adapted by the user. no problems, when using sqlceDataAdapter the data will be written to disk successfully.
But... i would like to add new data as well, so add data in the parent table, and data in the child table. These data will be added to the dataset first. After that i would like to write it to the database when the user wants to save the new data. To add data in the child table i need to know the id of the parent data, and there's the problem ! the id is specified as integer, auto incremented, and when adding data to the dataset, the id is not generated automatically.
when writing data to the database, the ids are filled in by sqlce, but i need these ids already before, when creating the child ids.
anybody an idea how solve this, without generating the ids myself ?
thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在数据集的插入命令中求助于 @@identity
You'll have to resort to @@identity in your insert command of the dataset