Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 数据表插入触发器_Vb.net_Ado - Fatal编程技术网

Vb.net 数据表插入触发器

Vb.net 数据表插入触发器,vb.net,ado,Vb.net,Ado,我想在dataset表上实现SQLINSERT触发器 我的应用程序有两个数据集表: ——表:Artikli-- IDB-int,自动递增 Sifra-int,主键 纳齐夫弦 Cena-双 PS-字符串 ——表:PodArtikli-- IDB-int,自动递增,主键 Sifra-int 纳齐夫弦 Cena-双 科里西纳-内特 Ukupno-计算列(Cena*Kolicina) 帕科万杰-双人 杰德,仅仅是一根绳子 PLU-字符串,唯一 欧洲标准化委员会-计算列(1000/Pakovanje*Ce

我想在dataset表上实现SQLINSERT触发器

我的应用程序有两个数据集表:

——表:Artikli--
IDB-int,自动递增
Sifra-int,主键
纳齐夫弦
Cena-双
PS-字符串

——表:PodArtikli--
IDB-int,自动递增,主键
Sifra-int
纳齐夫弦
Cena-双
科里西纳-内特
Ukupno-计算列(Cena*Kolicina)
帕科万杰-双人
杰德,仅仅是一根绳子
PLU-字符串,唯一
欧洲标准化委员会-计算列(1000/Pakovanje*Cena)

这些表通过外键约束进行关联,其中父表是
Artikli
,子表是
PodArtikli
Sifra
。 当一个新行被添加到
Artikli
中时,我想在
PodArtikli
表中自动添加新行,其中包含
Sifra、Naziv
Cena
表中添加行的值

数据集表中的数据显示在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

您不能在.NET
DataTable
中编写触发器,但可以使用
DataTable
事件实现类似的功能。例如,您可以执行
RowChanging
事件并执行changing行,查看是否添加了行,然后使用该行中的数据将新行插入子表

Private Sub Row_Changing(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
    If e.Action = DataRowAction.Add Then 
        Dim newChild as DataRow = childTable.NewRow()
        ' Get new row fr here and insert values 
        newChild("field") = e.Row("field")
        . . . . . . . 
        childTable.Rows.Add(newChild)
    End If
 End Sub

触发器通常在数据库中实现,尽管DataTable确实有一些事件。如果DGV绑定到数据源,则不必手动将数据传输到新行项目中。我也尝试了TableNewRow事件,但没有尝试任何方法。我使用了Row_Changed代替Row_Changed,因为在Row_Changed事件中,尚未实际添加行,并且引发异常InvalidConstraintException,表示子表中具有列“Sifra”值的行在父表中不存在。非常感谢。@Gruja82这很好。这正是我的尝试——引导你们进入正确的方向<代码>行更改或
行更改
-只是技术性的问题,您需要根据您的软件构造和执行流程来解决。享受。