[英]Assistance in join to MYSQL table in C#
I need Assistance please 我需要协助
I have two tables (X) And (Y) 我有两个表(X)和(Y)
Table (X) have { ID , material_Name , Material_number )
Table (Y) have { ID , Material_Name , Total )
Both appear on data gridview. 两者都出现在数据gridview上。
So, From table (X) i select the material_name from combobox. 因此,从表(X)中,我从组合框中选择了material_name。 then i write the number of material in the textbox.
然后我在文本框中输入材料的数量。 then i press add button to insert the value in the table(X).
然后我按添加按钮将值插入表(X)。
So let we assume From table (X) i selected the material_name is ( Pen) and the Material_number was (10).Then after three days i inserted the same material name but the material_number was (20). 因此,让我们假设从表(X)中我选择了material_name为(Pen),并且Material_number为(10)。然后三天后我插入了相同的材料名称,但material_number为(20)。 So the total Pin= 30 for now.
因此,目前总的Pin = 30。
So i want this result (30) appear to me on table (Y) in column (Total )on data Gridview. 所以我希望这个结果(30)在数据Gridview的(Total)列的表(Y)上显示给我。 And it can increase or decrease according to the inserting Material_number from table (X)
并且可以根据表(X)中插入的Material_number来增加或减少
As summary , 作为总结,
In Table (X) :- 在表(X)中:
First day >>> inserted 10 pens. & 5 soft
Second day >> inserted 20 pens .
The total pens that i have it in right now 10+20= (30). 我现在拥有的总笔数为10 + 20 =(30)。 And total soft that i have = (5).
我拥有的总软=(5)。
In Table(Y):- 在表(Y)中:
The result (30)pens should be appear to me in column (Material_number)in the row of pens.
And the result of soft (5)should be appear to me in the column ( Material_number ) in the row of Soft
. And the result of soft (5)should be appear to me in the column ( Material_number ) in the row of Soft
。
And like this for each material. 每种材料都这样。
How can i do this? 我怎样才能做到这一点?
An insert trigger will be run just before inserting into x. 插入触发器将在插入x之前运行。
CREATE TRIGGER insert_to_y BEFORE INSERT ON x
FOR EACH ROW
BEGIN
UPDATE Y SET total = total + NEW.material_number
WHERE Material_Name = NEW.Material_Name ;
END;
This way, when you run sql like this: 这样,当您像这样运行sql时:
insert into x(material_name, material_number) values('soft', 5)
It will automatically update y
to add the change. 它将自动更新
y
以添加更改。
Note that my example only handles updates. 请注意,我的示例仅处理更新。 If the value
soft
doesnt exist in the Y
table, nothing will be updated. 如果
Y
表中不存在soft
值,则不会更新任何内容。 But the trigger can be adjusted to handle that. 但是可以调整触发器以处理该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.