【发布时间】:2016-02-26 14:37:31
【问题描述】:
我想在数据集表上实现 sql 插入触发器。
我的应用有两个数据集表:
-- Table: Artikli --
IDB - int,autoincrement
Sifra - int, primary key
Naziv - string
Cena - double
PS - string
-- Table: PodArtikli --
IDB - int,autoincrement,primary key
Sifra - int
Naziv - string
Cena - double
Kolicina - int
Ukupno - computed column (Cena*Kolicina)
Pakovanje - double
Jed.Mere - string
PLU - string, unique
Cena_Po_Meri - computed column (1000/Pakovanje * Cena)
这些表通过外键约束关联,其中父表为Artikli,子表为PodArtikli,列Sifra。
我希望,当将新行添加到Artikli 时,自动在PodArtikli 表中添加新行,Sifra,Naziv 和Cena 值来自Artikli 表中添加的行。
数据集表中的数据显示在 DataGridView 中。
在按钮btnizmene 的点击事件上,我有以下代码:
Dim novirow As DataRow = dspetrovac.Artikli.NewRow
novirow("Sifra") = grdpodaci.Item(1, grdpodaci.CurrentRow.Index).Value
novirow("Naziv") = grdpodaci.Item(2, grdpodaci.CurrentRow.Index).Value
novirow("Cena") = grdpodaci.Item(3, grdpodaci.CurrentRow.Index).Value
novirow("PS") = grdpodaci.Item(4, grdpodaci.CurrentRow.Index).Value
【问题讨论】:
-
触发器通常在数据库中实现,尽管 DataTable 确实有一些事件。如果 DGV 绑定到数据源,则不必手动将数据穿梭到 newRow 项中
-
我也尝试过 TableNewRow 事件,但没有。